Ignore:
Timestamp:
Jan 27, 2008, 4:08:20 PM (14 years ago)
Author:
charles
Message:

#653 "overflow issue in Transmission/1.01" (1) safeguard bitfield functions against overflow. (2) add regression tests to see if this data is corrupted again in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r4404 r4840  
    152152}
    153153
    154 void tr_cpPieceAdd( tr_completion * cp, int piece )
     154void
     155tr_cpPieceAdd( tr_completion * cp, int piece )
    155156{
    156157    const tr_torrent * tor = cp->tor;
     
    163164}
    164165
    165 void tr_cpPieceRem( tr_completion * cp, int piece )
     166void
     167tr_cpPieceRem( tr_completion * cp, int piece )
    166168{
    167169    const tr_torrent * tor = cp->tor;
     
    190192    tr_bitfieldRemRange ( cp->blockBitfield, start, end );
    191193    tr_bitfieldRem( cp->pieceBitfield, piece );
     194
     195    assert( cp->completeHave <= tor->info.totalSize );
     196    assert( cp->doneHave <= tor->info.totalSize );
     197    assert( cp->doneHave <= cp->completeHave );
    192198}
    193199
     
    219225            cp->doneHave += blockSize;
    220226    }
     227
     228    assert( cp->completeHave <= tor->info.totalSize );
     229    assert( cp->doneHave <= tor->info.totalSize );
     230    assert( cp->doneHave <= cp->completeHave );
    221231}
    222232
     
    263273tr_cpLeftUntilComplete ( const tr_completion * cp )
    264274{
     275    assert( cp->tor->info.totalSize >= cp->completeHave );
     276
    265277    return cp->tor->info.totalSize - cp->completeHave;
    266278}
     
    285297tr_cpGetStatus ( const tr_completion * cp )
    286298{
    287     if( cp->completeHave >= cp->tor->info.totalSize )
     299    assert( cp->tor->info.totalSize >= cp->completeHave );
     300
     301    if( cp->completeHave == cp->tor->info.totalSize )
    288302        return TR_CP_COMPLETE;
    289303
Note: See TracChangeset for help on using the changeset viewer.