(trunk, libT) #5097 'Rare buffer overflow (piece index too big)' -- fixed.

This commit is contained in:
Jordan Lee 2012-10-20 15:57:56 +00:00
parent fcf5690476
commit a981f4b6a6
1 changed files with 9 additions and 1 deletions

View File

@ -549,10 +549,18 @@ onTrackerResponse( tr_torrent * tor, const tr_tracker_event * event, void * unus
static tr_piece_index_t
getBytePiece( const tr_info * info, uint64_t byteOffset )
{
tr_piece_index_t piece;
assert( info );
assert( info->pieceSize != 0 );
return byteOffset / info->pieceSize;
piece = byteOffset / info->pieceSize;
/* handle 0-byte files at the end of a torrent */
if (byteOffset == info->totalSize)
piece = info->pieceCount - 1;
return piece;
}
static void