fixed uninitialized variable in utp MTU logic. Fixed array overrun in disk cache
This commit is contained in:
parent
8c3ad6b4f3
commit
daea6d507e
|
@ -1271,7 +1271,7 @@ namespace libtorrent
|
||||||
int block = j.offset / m_block_size;
|
int block = j.offset / m_block_size;
|
||||||
int block_offset = j.offset & (m_block_size-1);
|
int block_offset = j.offset & (m_block_size-1);
|
||||||
int size = j.buffer_size;
|
int size = j.buffer_size;
|
||||||
int min_blocks_to_read = block_offset > 0 ? 2 : 1;
|
int min_blocks_to_read = block_offset > 0 && (size > m_block_size - block_offset) ? 2 : 1;
|
||||||
TORRENT_ASSERT(size <= m_block_size);
|
TORRENT_ASSERT(size <= m_block_size);
|
||||||
int start_block = block;
|
int start_block = block;
|
||||||
// if we have to read more than one block, and
|
// if we have to read more than one block, and
|
||||||
|
@ -1280,6 +1280,12 @@ namespace libtorrent
|
||||||
if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1)
|
if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1)
|
||||||
++start_block;
|
++start_block;
|
||||||
|
|
||||||
|
#ifdef TORRENT_DEBUG
|
||||||
|
int piece_size = j.storage->info()->piece_size(j.piece);
|
||||||
|
int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size;
|
||||||
|
TORRENT_ASSERT(start_block < blocks_in_piece);
|
||||||
|
#endif
|
||||||
|
|
||||||
return p.blocks[start_block].buf != 0;
|
return p.blocks[start_block].buf != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1293,11 +1299,16 @@ namespace libtorrent
|
||||||
int block_offset = j.offset & (m_block_size-1);
|
int block_offset = j.offset & (m_block_size-1);
|
||||||
int buffer_offset = 0;
|
int buffer_offset = 0;
|
||||||
int size = j.buffer_size;
|
int size = j.buffer_size;
|
||||||
int min_blocks_to_read = block_offset > 0 ? 2 : 1;
|
int min_blocks_to_read = block_offset > 0 && (size > m_block_size - block_offset) ? 2 : 1;
|
||||||
TORRENT_ASSERT(size <= m_block_size);
|
TORRENT_ASSERT(size <= m_block_size);
|
||||||
int start_block = block;
|
int start_block = block;
|
||||||
if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1)
|
if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1)
|
||||||
++start_block;
|
++start_block;
|
||||||
|
|
||||||
|
int piece_size = j.storage->info()->piece_size(j.piece);
|
||||||
|
int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size;
|
||||||
|
TORRENT_ASSERT(start_block < blocks_in_piece);
|
||||||
|
|
||||||
// if block_offset > 0, we need to read two blocks, and then
|
// if block_offset > 0, we need to read two blocks, and then
|
||||||
// copy parts of both, because it's not aligned to the block
|
// copy parts of both, because it's not aligned to the block
|
||||||
// boundaries
|
// boundaries
|
||||||
|
@ -1307,8 +1318,6 @@ namespace libtorrent
|
||||||
// space to force hitting disk without caching anything
|
// space to force hitting disk without caching anything
|
||||||
if (m_settings.explicit_read_cache) return -2;
|
if (m_settings.explicit_read_cache) return -2;
|
||||||
|
|
||||||
int piece_size = j.storage->info()->piece_size(j.piece);
|
|
||||||
int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size;
|
|
||||||
int end_block = start_block;
|
int end_block = start_block;
|
||||||
while (end_block < blocks_in_piece && p.blocks[end_block].buf == 0) ++end_block;
|
while (end_block < blocks_in_piece && p.blocks[end_block].buf == 0) ++end_block;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace libtorrent
|
||||||
, m_last_socket(0)
|
, m_last_socket(0)
|
||||||
, m_new_connection(-1)
|
, m_new_connection(-1)
|
||||||
, m_sett(sett)
|
, m_sett(sett)
|
||||||
|
, m_last_route_update(min_time())
|
||||||
, m_sock_buf_size(0)
|
, m_sock_buf_size(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue