Changeset 14550


Ignore:
Timestamp:
Jul 5, 2015, 7:54:46 AM (7 years ago)
Author:
mikedld
Message:

#5912: Prevent completed pieces modification by webseeds (patch by cfpp2p)

This avoids blocks corruption in case webseed provides bad data.

As explained by cfpp2p, "The requirements to reproduce are at least one
webseed that sends corrupt block(s), and at least one other peer (webseed
or regular peer) that sends correct data for the same block. Then a peer
with correct block sends the block and transmission accepts and verifies
that block as good. But then the webseed thread comes around and the same
block is downloaded from the webseed that sends a bad block which is then
written even though the piece was previously deemed complete."

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/webseed.c

    r14428 r14550  
    163163      const tr_piece_index_t piece = data->piece_index;
    164164
    165       while (len > 0)
     165      if (!tr_torrentPieceIsComplete (tor, piece))
    166166        {
    167           const uint32_t bytes_this_pass = MIN (len, block_size);
    168           tr_cacheWriteBlock (cache, tor, piece, offset_end - len, bytes_this_pass, buf);
    169           len -= bytes_this_pass;
     167          while (len > 0)
     168            {
     169              const uint32_t bytes_this_pass = MIN (len, block_size);
     170              tr_cacheWriteBlock (cache, tor, piece, offset_end - len, bytes_this_pass, buf);
     171              len -= bytes_this_pass;
     172            }
     173
     174          fire_client_got_blocks (tor, w, data->block_index, data->count);
    170175        }
    171 
    172       fire_client_got_blocks (tor, w, data->block_index, data->count);
    173176    }
    174177
     
    423426            else
    424427            {
    425               if (buf_len)
     428              if (buf_len && !tr_torrentPieceIsComplete (tor, t->piece_index))
    426429                {
    427430                  /* on_content_changed () will not write a block if it is smaller than
Note: See TracChangeset for help on using the changeset viewer.