Ticket #5969: 5969.crash.fix.patch

File 5969.crash.fix.patch, 1.8 KB (added by x190, 6 years ago)
  • libtransmission/webseed.c

     
    222222****
    223223***/
    224224
     225static bool
     226piece_offset_is_valid (tr_torrent * tor, struct tr_webseed_task * t)
     227{
     228  bool is_valid;
     229
     230  is_valid = evbuffer_get_length (t->content) <= t->length - (t->blocks_done * tor->blockSize);
     231
     232  return is_valid;
     233}
     234
    225235static void
    226236on_content_changed (struct evbuffer                * buf,
    227237                    const struct evbuffer_cb_info  * info,
     
    237247    {
    238248      uint32_t len;
    239249      struct tr_webseed * w = task->webseed;
     250      tr_torrent * tor = tr_torrentFindFromId (w->session, w->torrent_id);
    240251
    241252      tr_bandwidthUsed (&w->bandwidth, TR_DOWN, n_added, true, tr_time_msec ());
    242253      fire_client_got_piece_data (w, n_added);
    243254      len = evbuffer_get_length (buf);
    244255
    245       if (!task->response_code)
     256      if (!task->response_code && piece_offset_is_valid (tor, task))
    246257        {
    247258          tr_webGetTaskInfo (task->web_task, TR_WEB_GET_CODE, &task->response_code);
    248259
     
    266277            }
    267278        }
    268279
    269       if ((task->response_code == 206) && (len >= task->block_size))
     280      if ((task->response_code == 206) && (len >= task->block_size) && piece_offset_is_valid (tor, task))
    270281        {
    271282          /* once we've got at least one full block, save it */
    272283
     
    363374    }
    364375}
    365376
    366 
    367377static void
    368378web_response_func (tr_session    * session,
    369379                   bool            did_connect UNUSED,
     
    393403      if (t->response_code == 206)
    394404        --w->active_transfers;
    395405
    396       if (!success)
     406      if (!success || !piece_offset_is_valid (tor, t))
    397407        {
    398408          const tr_block_index_t blocks_remain = (t->length + tor->blockSize - 1)
    399409                                                   / tor->blockSize - t->blocks_done;