fix buffer offset bug recently introduced to disk_io_thread::do_read()
This commit is contained in:
parent
eae4307da2
commit
c426ba88d4
|
@ -1307,7 +1307,8 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
|
|||
// if this is the last piece, adjust the size of the
|
||||
// last buffer to match up
|
||||
iov[iov_len - 1] = iov[iov_len - 1].first(aux::numeric_cast<std::size_t>(
|
||||
std::min(piece_size - (iov_len - 1) * default_block_size, default_block_size)));
|
||||
std::min(piece_size - int(adjusted_offset) - (iov_len - 1)
|
||||
* default_block_size, default_block_size)));
|
||||
TORRENT_ASSERT(iov[iov_len - 1].size() > 0);
|
||||
|
||||
// at this point, all the buffers are allocated and iov is initialized
|
||||
|
@ -1570,9 +1571,8 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
|
|||
, storage_error const& se)> handler, disk_job_flags_t const flags)
|
||||
{
|
||||
TORRENT_ASSERT(r.length <= default_block_size);
|
||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||
|
||||
DLOG("do_read piece: %d block: %d\n", static_cast<int>(r.piece)
|
||||
DLOG("async_read piece: %d block: %d\n", static_cast<int>(r.piece)
|
||||
, r.start / default_block_size);
|
||||
|
||||
disk_io_job* j = allocate_job(job_action_t::read);
|
||||
|
@ -1584,6 +1584,9 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
|
|||
j->flags = flags;
|
||||
j->callback = std::move(handler);
|
||||
|
||||
TORRENT_ASSERT(static_cast<int>(r.piece) * static_cast<std::int64_t>(j->storage->files().piece_length())
|
||||
+ r.start + r.length <= j->storage->files().total_size());
|
||||
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
int const ret = prep_read_job_impl(j);
|
||||
l.unlock();
|
||||
|
|
|
@ -120,6 +120,8 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
const int size = bufs_size(bufs);
|
||||
TORRENT_ASSERT(size > 0);
|
||||
TORRENT_ASSERT(static_cast<int>(piece) * static_cast<std::int64_t>(files.piece_length())
|
||||
+ offset + size <= files.total_size());
|
||||
|
||||
// find the file iterator and file offset
|
||||
std::int64_t const torrent_offset = static_cast<int>(piece) * std::int64_t(files.piece_length()) + offset;
|
||||
|
|
Loading…
Reference in New Issue