forked from premiere/premiere-libtorrent
Merge pull request #425 from arvidn/map-block-1.1
add run-time check to file_storage::map_block
This commit is contained in:
commit
6ab158de62
|
@ -334,6 +334,13 @@ namespace libtorrent
|
|||
// returns a list of file_slice objects representing the portions of
|
||||
// files the specified piece index, byte offset and size range overlaps.
|
||||
// this is the inverse mapping of map_file().
|
||||
//
|
||||
// Preconditions of this function is that the input range is within the
|
||||
// torrents address space. ``piece`` may not be negative and
|
||||
//
|
||||
// ``piece`` * piece_size + ``offset`` + ``size``
|
||||
//
|
||||
// may not exceed the total size of the torrent.
|
||||
std::vector<file_slice> map_block(int piece, boost::int64_t offset
|
||||
, int size) const;
|
||||
|
||||
|
|
|
@ -419,7 +419,8 @@ namespace libtorrent
|
|||
return m_files[index].name_len;
|
||||
}
|
||||
|
||||
std::vector<file_slice> file_storage::map_block(int piece, boost::int64_t offset
|
||||
std::vector<file_slice> file_storage::map_block(int const piece
|
||||
, boost::int64_t const offset
|
||||
, int size) const
|
||||
{
|
||||
TORRENT_ASSERT_PRECOND(num_files() > 0);
|
||||
|
@ -433,6 +434,10 @@ namespace libtorrent
|
|||
TORRENT_ASSERT_PRECOND(boost::int64_t(target.offset + size) <= m_total_size);
|
||||
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
||||
|
||||
// in case the size is past the end, fix it up
|
||||
if (boost::int64_t(target.offset + size) > m_total_size)
|
||||
size = m_total_size - target.offset;
|
||||
|
||||
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
||||
m_files.begin(), m_files.end(), target, compare_file_offset);
|
||||
|
||||
|
|
Loading…
Reference in New Issue