make sure torrent_info::is_valid returns false when the file fails to load
This commit is contained in:
parent
a07ffe42f8
commit
c7c204280a
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue