diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index c8fd9d5ad..3dbe11542 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1013,7 +1013,8 @@ namespace { // we want this division to round upwards, that's why we have the // extra addition - if (files.total_size() >= std::numeric_limits::max() + if (files.total_size() >= + (std::numeric_limits::max() / files.piece_length()) - files.piece_length()) { ec = errors::too_many_pieces_in_torrent; diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 8118ad793..6e15bd091 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -126,6 +126,7 @@ static test_torrent_t test_torrents[] = { "unordered.torrent" }, { "symlink_zero_size.torrent" }, { "pad_file_no_path.torrent" }, + { "large.torrent" }, }; struct test_failing_torrent_t diff --git a/test/test_torrents/large.torrent b/test/test_torrents/large.torrent new file mode 100644 index 000000000..3056ec695 Binary files /dev/null and b/test/test_torrents/large.torrent differ