diff --git a/ChangeLog b/ChangeLog index b3393ea0c..c0cee8678 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * make torrent_info::is_valid() return false if torrent failed to load * fix per-torrent rate limits for >256 peer classes * don't load user_agent and peer_fingerprint from session_state * fix file rename issue with name prefix matching torrent name diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 78d2b67f7..5f2e66a56 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -388,6 +388,8 @@ namespace libtorrent TORRENT_ASSERT(ti.num_files() > 0); TORRENT_ASSERT(ti.total_size() > 0); + if (!ti.is_valid()) return; + if (ti.creation_date()) m_creation_date = *ti.creation_date(); if (!ti.creator().empty()) set_creator(ti.creator().c_str()); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 04508c259..8dc50188b 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1249,6 +1249,8 @@ namespace libtorrent if (!name_ent) { ec = errors::torrent_missing_name; + // mark the torrent as invalid + m_files.set_piece_length(0); return false; } @@ -1266,14 +1268,22 @@ namespace libtorrent // this is the counter used to name pad files int pad_file_cnt = 0; if (!extract_single_file(info, files, "", info_ptr_diff, true, pad_file_cnt, ec)) + { + // mark the torrent as invalid + m_files.set_piece_length(0); return false; + } m_multifile = false; } else { if (!extract_files(files_node, files, name, info_ptr_diff, ec)) + { + // mark the torrent as invalid + m_files.set_piece_length(0); return false; + } m_multifile = true; } TORRENT_ASSERT(!files.name().empty()); @@ -1290,6 +1300,8 @@ namespace libtorrent if (!pieces && !root_hash) { ec = errors::torrent_missing_pieces; + // mark the torrent as invalid + m_files.set_piece_length(0); return false; } @@ -1298,6 +1310,8 @@ namespace libtorrent if (pieces.string_length() != files.num_pieces() * 20) { ec = errors::torrent_invalid_hashes; + // mark the torrent as invalid + m_files.set_piece_length(0); return false; } @@ -1311,6 +1325,8 @@ namespace libtorrent if (root_hash.string_length() != 20) { ec = errors::torrent_invalid_hashes; + // mark the torrent as invalid + m_files.set_piece_length(0); return false; } int num_leafs = merkle_num_leafs(files.num_pieces()); @@ -1318,6 +1334,8 @@ namespace libtorrent if (num_nodes - num_leafs >= (2<<24)) { ec = errors::too_many_pieces_in_torrent; + // mark the torrent as invalid + m_files.set_piece_length(0); return false; } m_merkle_first_leaf = num_nodes - num_leafs; diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index d0a0301cc..e2f80782c 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -775,6 +775,7 @@ TORRENT_TEST(parse_torrents) fprintf(stdout, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str() , test_error_torrents[i].error.message().c_str()); TEST_CHECK(ec.message() == test_error_torrents[i].error.message()); + TEST_EQUAL(ti->is_valid(), false); } }