mirror of
https://github.com/transmission/transmission
synced 2024-12-23 00:04:06 +00:00
#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."
This commit is contained in:
parent
6cbfcdc85e
commit
b9adf279ca
1 changed files with 10 additions and 7 deletions
|
@ -162,14 +162,17 @@ write_block_func (void * vdata)
|
|||
tr_cache * cache = data->session->cache;
|
||||
const tr_piece_index_t piece = data->piece_index;
|
||||
|
||||
while (len > 0)
|
||||
if (!tr_torrentPieceIsComplete (tor, piece))
|
||||
{
|
||||
const uint32_t bytes_this_pass = MIN (len, block_size);
|
||||
tr_cacheWriteBlock (cache, tor, piece, offset_end - len, bytes_this_pass, buf);
|
||||
len -= bytes_this_pass;
|
||||
}
|
||||
while (len > 0)
|
||||
{
|
||||
const uint32_t bytes_this_pass = MIN (len, block_size);
|
||||
tr_cacheWriteBlock (cache, tor, piece, offset_end - len, bytes_this_pass, buf);
|
||||
len -= bytes_this_pass;
|
||||
}
|
||||
|
||||
fire_client_got_blocks (tor, w, data->block_index, data->count);
|
||||
fire_client_got_blocks (tor, w, data->block_index, data->count);
|
||||
}
|
||||
}
|
||||
|
||||
evbuffer_free (buf);
|
||||
|
@ -422,7 +425,7 @@ web_response_func (tr_session * session,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (buf_len)
|
||||
if (buf_len && !tr_torrentPieceIsComplete (tor, t->piece_index))
|
||||
{
|
||||
/* on_content_changed () will not write a block if it is smaller than
|
||||
the torrent's block size, i.e. the torrent's very last block */
|
||||
|
|
Loading…
Reference in a new issue