Ignore:
Timestamp:
Aug 5, 2008, 8:27:40 PM (13 years ago)
Author:
charles
Message:

#1135: crashes when adding torrent, with "assert( ( info->pieceSize % tor->blockSize ) == 0 );"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r6425 r6429  
    390390static void torrentStart( tr_torrent * tor, int reloadProgress );
    391391
     392/**
     393 * Decide on a block size.  constraints:
     394 * (1) most clients decline requests over 16 KiB
     395 * (2) pieceSize must be a multiple of block size
     396 */
     397static uint32_t
     398getBlockSize( uint32_t pieceSize )
     399{
     400    uint32_t b = pieceSize;
     401    while( b > MAX_BLOCK_SIZE )
     402        b /= 2u;
     403    if( pieceSize % b ) /* not cleanly divisible */
     404        return 0;
     405    return b;
     406}
     407
    392408static void
    393409torrentRealInit( tr_handle     * h,
     
    408424    randomizeTiers( info );
    409425
    410     /**
    411      * Decide on a block size.  constraints:
    412      * (1) most clients decline requests over 16 KiB
    413      * (2) pieceSize must be a multiple of block size
    414      */
    415     tor->blockSize = info->pieceSize;
    416     while( tor->blockSize > MAX_BLOCK_SIZE )
    417         tor->blockSize /= 2;
     426    tor->blockSize = getBlockSize( info->pieceSize );
    418427
    419428    tor->lastPieceSize = info->totalSize % info->pieceSize;
     
    544553    err = tr_metainfoParse( handle, setmeInfo, metainfo );
    545554    doFree = !err && ( setmeInfo == &tmp );
     555
     556    if( !getBlockSize( setmeInfo->pieceSize ) )
     557        err = TR_EINVALID;
    546558
    547559    if( !err && tr_torrentExists( handle, setmeInfo->hash ) )
Note: See TracChangeset for help on using the changeset viewer.