Skip to content

Commit 5441874

Browse files
committed
fix integer overflow in whole_pieces_threshold logic
1 parent 7f4566c commit 5441874

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
1.1.5 release
33

4+
* fix integer overflow in whole_pieces_threshold logic
45
* fix uTP path MTU discovery issue on windows (DF bit was not set correctly)
56
* fix python binding for torrent_handle, to be hashable
67
* fix IPv6 tracker support by performing the second announce in more cases

src/request_blocks.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,16 @@ namespace libtorrent
110110

111111
int prefer_contiguous_blocks = c.prefer_contiguous_blocks();
112112

113-
if (prefer_contiguous_blocks == 0 && !time_critical_mode)
113+
if (prefer_contiguous_blocks == 0
114+
&& !time_critical_mode
115+
&& t.settings().get_int(settings_pack::whole_pieces_threshold) > 0)
114116
{
115-
int blocks_per_piece = t.torrent_file().piece_length() / t.block_size();
116-
prefer_contiguous_blocks = c.statistics().download_payload_rate()
117-
* t.settings().get_int(settings_pack::whole_pieces_threshold)
118-
> t.torrent_file().piece_length() ? blocks_per_piece : 0;
117+
int const blocks_per_piece = t.torrent_file().piece_length() / t.block_size();
118+
prefer_contiguous_blocks
119+
= (c.statistics().download_payload_rate()
120+
> t.torrent_file().piece_length()
121+
/ t.settings().get_int(settings_pack::whole_pieces_threshold))
122+
? blocks_per_piece : 0;
119123
}
120124

121125
// if we prefer whole pieces, the piece picker will pick at least

0 commit comments

Comments
 (0)