fix error handling of merkle torrents

This commit is contained in:
arvidn 2018-01-13 14:36:13 +01:00 committed by Arvid Norberg
parent f29bb69612
commit a9085db760
5 changed files with 13 additions and 2 deletions

View File

@ -1,4 +1,5 @@
* fix error handling of some merkle torrents
* fix error handling of unsupported hard-links * fix error handling of unsupported hard-links
1.1.6 release 1.1.6 release

View File

@ -1258,8 +1258,15 @@ namespace libtorrent
m_files.set_piece_length(0); m_files.set_piece_length(0);
return false; return false;
} }
int num_leafs = merkle_num_leafs(files.num_pieces()); if (files.num_pieces() <= 0)
int num_nodes = merkle_num_nodes(num_leafs); {
ec = errors::no_files_in_torrent;
// mark the torrent as invalid
m_files.set_piece_length(0);
return false;
}
int const num_leafs = merkle_num_leafs(files.num_pieces());
int const num_nodes = merkle_num_nodes(num_leafs);
if (num_nodes - num_leafs >= (2<<24)) if (num_nodes - num_leafs >= (2<<24))
{ {
ec = errors::too_many_pieces_in_torrent; ec = errors::too_many_pieces_in_torrent;

View File

@ -70,6 +70,7 @@ EXTRA_DIST = Jamfile \
test_torrents/httpseed.torrent \ test_torrents/httpseed.torrent \
test_torrents/invalid_file_size.torrent \ test_torrents/invalid_file_size.torrent \
test_torrents/invalid_info.torrent \ test_torrents/invalid_info.torrent \
test_torrents/invalid_merkle.torrent \
test_torrents/invalid_name.torrent \ test_torrents/invalid_name.torrent \
test_torrents/invalid_name2.torrent \ test_torrents/invalid_name2.torrent \
test_torrents/invalid_name3.torrent \ test_torrents/invalid_name3.torrent \

View File

@ -161,6 +161,7 @@ test_failing_torrent_t test_error_torrents[] =
{ "unaligned_pieces.torrent", errors::torrent_invalid_hashes }, { "unaligned_pieces.torrent", errors::torrent_invalid_hashes },
{ "invalid_root_hash.torrent", errors::torrent_invalid_hashes }, { "invalid_root_hash.torrent", errors::torrent_invalid_hashes },
{ "invalid_root_hash2.torrent", errors::torrent_missing_pieces }, { "invalid_root_hash2.torrent", errors::torrent_missing_pieces },
{ "invalid_merkle.torrent", errors::no_files_in_torrent},
{ "invalid_file_size.torrent", errors::torrent_invalid_length }, { "invalid_file_size.torrent", errors::torrent_invalid_length },
{ "invalid_symlink.torrent", errors::torrent_invalid_name }, { "invalid_symlink.torrent", errors::torrent_invalid_name },
}; };

View File

@ -0,0 +1 @@
d10:cion datei15992e4:infod6:lengthi000e4:name4:temp12:piece lengthi12e9:root hash20:‚ž¼Œ&¾ÇJW}ÜA4u,·¼‡ee