fix issue in reading resume data

This commit is contained in:
arvidn 2020-04-11 03:16:31 +02:00 committed by Arvid Norberg
parent 5c33fe25c5
commit c825320df8
5 changed files with 108 additions and 1 deletions

View File

@ -1,3 +1,4 @@
* fix issue in reading resume data
* revert NXDOMAIN change from 1.2.4
* don't open any listen sockets if listen_interfaces is empty or misconfigured
* fix bug in auto disk cache size logic

View File

@ -1116,6 +1116,7 @@ TORRENT_TEST(tracker_ipv6_argument)
pack.set_str(settings_pack::listen_interfaces, "123.0.0.3:0,[ffff::1337]:0");
ses.apply_settings(pack);
p.ti = make_torrent(true);
p.info_hash.clear();
return 60;
},
[&](std::string method, std::string req
@ -1154,6 +1155,7 @@ TORRENT_TEST(tracker_key_argument)
[](lt::add_torrent_params& p, lt::session&)
{
p.ti = make_torrent(true);
p.info_hash.clear();
return 60;
},
[&](std::string, std::string req
@ -1184,6 +1186,7 @@ TORRENT_TEST(tracker_ipv6_argument_non_private)
pack.set_bool(settings_pack::anonymous_mode, false);
ses.apply_settings(pack);
p.ti = make_torrent(false);
p.info_hash.clear();
return 60;
},
[&](std::string method, std::string req
@ -1212,6 +1215,7 @@ TORRENT_TEST(tracker_ipv6_argument_privacy_mode)
pack.set_bool(settings_pack::anonymous_mode, true);
ses.apply_settings(pack);
p.ti = make_torrent(true);
p.info_hash.clear();
return 60;
},
[&](std::string method, std::string req
@ -1240,6 +1244,7 @@ TORRENT_TEST(tracker_user_agent_privacy_mode_public_torrent)
pack.set_str(settings_pack::user_agent, "test_agent/1.2.3");
ses.apply_settings(pack);
p.ti = make_torrent(false);
p.info_hash.clear();
return 60;
},
[&](std::string method, std::string req
@ -1267,6 +1272,7 @@ TORRENT_TEST(tracker_user_agent_privacy_mode_private_torrent)
pack.set_str(settings_pack::user_agent, "test_agent/1.2.3");
ses.apply_settings(pack);
p.ti = make_torrent(true);
p.info_hash.clear();
return 60;
},
[&](std::string method, std::string req

View File

@ -4829,6 +4829,14 @@ namespace {
return std::make_pair(ptr_t(), false);
}
if (params.ti
&& !params.info_hash.is_all_zeros()
&& params.info_hash != params.ti->info_hash())
{
ec = errors::mismatching_info_hash;
return std::make_pair(ptr_t(), false);
}
#ifndef TORRENT_DISABLE_DHT
// add params.dht_nodes to the DHT, if enabled
for (auto const& n : params.dht_nodes)

View File

@ -1873,6 +1873,9 @@ bool is_downloading_state(int const st)
if (m_add_torrent_params)
{
piece_index_t idx(0);
if (m_add_torrent_params->piece_priorities.size() > std::size_t(m_torrent_file->num_pieces()))
m_add_torrent_params->piece_priorities.resize(std::size_t(m_torrent_file->num_pieces()));
for (auto prio : m_add_torrent_params->piece_priorities)
{
if (has_picker() || prio != default_priority)
@ -5054,7 +5057,12 @@ bool is_downloading_state(int const st)
INVARIANT_CHECK;
// this call is only valid on torrents with metadata
TORRENT_ASSERT(valid_metadata());
if (!valid_metadata())
{
pieces->clear();
return;
}
if (!has_picker())
{
pieces->clear();

View File

@ -277,6 +277,7 @@ TORRENT_TEST(added_peers)
add_torrent_params p = parse_magnet_uri(
"magnet:?xt=urn:btih:abababababababababababababababababababab&x.pe=127.0.0.1:48081&x.pe=127.0.0.2:48082");
p.ti = info;
p.info_hash.clear();
p.save_path = ".";
torrent_handle h = ses.add_torrent(std::move(p));
@ -290,6 +291,89 @@ TORRENT_TEST(added_peers)
if (ra) TEST_EQUAL(ra->params.peers.size(), 2);
}
TORRENT_TEST(mismatching_info_hash)
{
file_storage fs;
fs.add_file("test_torrent_dir4/tmp1", 1024);
lt::create_torrent t(fs, 1024);
std::vector<char> tmp;
bencode(std::back_inserter(tmp), t.generate());
auto info = std::make_shared<torrent_info>(tmp, from_span);
add_torrent_params p;
p.ti = std::move(info);
// this info-hash is definitely different from the one in `info`, this
// should trigger a failure
p.info_hash = lt::sha1_hash("01010101010101010101");
p.save_path = ".";
lt::session ses(settings());
error_code ec;
torrent_handle h = ses.add_torrent(std::move(p), ec);
TEST_CHECK(ec == lt::errors::mismatching_info_hash);
TEST_CHECK(!h.is_valid());
}
TORRENT_TEST(exceed_file_prio)
{
file_storage fs;
fs.add_file("test_torrent_dir4/tmp1", 1024);
lt::create_torrent t(fs, 1024);
std::vector<char> tmp;
bencode(std::back_inserter(tmp), t.generate());
auto info = std::make_shared<torrent_info>(tmp, from_span);
add_torrent_params p;
p.ti = std::move(info);
p.file_priorities.resize(9999, lt::low_priority);
p.save_path = ".";
lt::session ses(settings());
error_code ec;
torrent_handle h = ses.add_torrent(std::move(p));
auto const prios = h.get_file_priorities();
TEST_CHECK(prios.size() == 1);
}
TORRENT_TEST(exceed_piece_prio)
{
file_storage fs;
fs.add_file("test_torrent_dir4/tmp1", 1024);
lt::create_torrent t(fs, 1024);
std::vector<char> tmp;
bencode(std::back_inserter(tmp), t.generate());
auto info = std::make_shared<torrent_info>(tmp, from_span);
std::size_t const num_pieces = std::size_t(info->num_pieces());
add_torrent_params p;
p.ti = std::move(info);
p.piece_priorities.resize(9999, lt::low_priority);
p.save_path = ".";
lt::session ses(settings());
error_code ec;
torrent_handle h = ses.add_torrent(std::move(p));
auto const prios = h.get_piece_priorities();
TEST_CHECK(prios.size() == num_pieces);
}
TORRENT_TEST(exceed_piece_prio_magnet)
{
add_torrent_params p;
p.info_hash = sha1_hash("abababababababababab");
p.piece_priorities.resize(9999, lt::low_priority);
p.save_path = ".";
lt::session ses(settings());
error_code ec;
torrent_handle h = ses.add_torrent(std::move(p));
auto const prios = h.get_piece_priorities();
TEST_CHECK(prios.empty());
}
TORRENT_TEST(torrent)
{
/* {