merged fixes from RC_0_16

This commit is contained in:
Arvid Norberg 2013-12-23 01:40:05 +00:00
parent ff1b06871e
commit 444223c2e3
7 changed files with 52 additions and 16 deletions

View File

@ -26,6 +26,9 @@
* fix uTP edge case where udp socket buffer fills up * fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP * fix nagle implementation in uTP
* deduplicate web seed entries from torrent files
* improve error reporting from lazy_decode()
0.16.13 release 0.16.13 release
* fix auto-manage issue when pausing session * fix auto-manage issue when pausing session

View File

@ -267,7 +267,7 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
lazy_entry e; lazy_entry e;
int pos; int pos = -1;
printf("decoding. recursion limit: %d total item count limit: %d\n" printf("decoding. recursion limit: %d total item count limit: %d\n"
, depth_limit, item_limit); , depth_limit, item_limit);
ret = lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos ret = lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos

View File

@ -61,15 +61,22 @@ namespace libtorrent
// first occurance of the delimiter is interpreted as an int. // first occurance of the delimiter is interpreted as an int.
// return the pointer to the delimiter, or 0 if there is a // return the pointer to the delimiter, or 0 if there is a
// parse error. val should be initialized to zero // parse error. val should be initialized to zero
char const* parse_int(char const* start, char const* end, char delimiter, boost::int64_t& val) char const* parse_int(char const* start, char const* end, char delimiter
, boost::int64_t& val, bdecode_errors::error_code_enum& ec)
{ {
while (start < end && *start != delimiter) while (start < end && *start != delimiter)
{ {
if (!numeric(*start)) { return 0; } if (!numeric(*start))
{
ec = bdecode_errors::expected_string;
return start;
}
val *= 10; val *= 10;
val += *start - '0'; val += *start - '0';
++start; ++start;
} }
if (*start != delimiter)
ec = bdecode_errors::expected_colon;
return start; return start;
} }
@ -124,9 +131,14 @@ namespace libtorrent
} }
if (!numeric(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_string); if (!numeric(t)) TORRENT_FAIL_BDECODE(bdecode_errors::expected_string);
boost::int64_t len = t - '0'; boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len); bdecode_errors::error_code_enum e = bdecode_errors::no_error;
if (start == 0 || start + len + 3 > end || *start != ':') start = parse_int(start, end, ':', len, e);
TORRENT_FAIL_BDECODE(bdecode_errors::expected_colon); if (e)
TORRENT_FAIL_BDECODE(e);
if (start + len + 1 > end)
TORRENT_FAIL_BDECODE(errors::unexpected_eof);
++start; ++start;
if (start == end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof); if (start == end) TORRENT_FAIL_BDECODE(bdecode_errors::unexpected_eof);
lazy_entry* ent = top->dict_append(start); lazy_entry* ent = top->dict_append(start);
@ -183,9 +195,12 @@ namespace libtorrent
TORRENT_FAIL_BDECODE(bdecode_errors::expected_value); TORRENT_FAIL_BDECODE(bdecode_errors::expected_value);
boost::int64_t len = t - '0'; boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len); bdecode_errors::error_code_enum e = bdecode_errors::no_error;
if (start == 0 || start + len + 1 > end || *start != ':') start = parse_int(start, end, ':', len, e);
TORRENT_FAIL_BDECODE(bdecode_errors::expected_colon); if (e)
TORRENT_FAIL_BDECODE(e);
if (start + len + 1 > end)
TORRENT_FAIL_BDECODE(errors::unexpected_eof);
++start; ++start;
top->construct_string(start, int(len)); top->construct_string(start, int(len));
stack.pop_back(); stack.pop_back();
@ -204,7 +219,10 @@ namespace libtorrent
boost::int64_t val = 0; boost::int64_t val = 0;
bool negative = false; bool negative = false;
if (*m_data.start == '-') negative = true; if (*m_data.start == '-') negative = true;
parse_int(negative?m_data.start+1:m_data.start, m_data.start + m_size, 'e', val); bdecode_errors::error_code_enum ec = bdecode_errors::no_error;
parse_int(negative?m_data.start+1:m_data.start
, m_data.start + m_size, 'e', val, ec);
TORRENT_ASSERT(!ec);
if (negative) val = -val; if (negative) val = -val;
return val; return val;
} }

View File

@ -1280,6 +1280,8 @@ namespace libtorrent
} }
else if (url_seeds && url_seeds->type() == lazy_entry::list_t) else if (url_seeds && url_seeds->type() == lazy_entry::list_t)
{ {
// only add a URL once
std::set<std::string> unique;
for (int i = 0, end(url_seeds->list_size()); i < end; ++i) for (int i = 0, end(url_seeds->list_size()); i < end; ++i)
{ {
lazy_entry const* url = url_seeds->list_at(i); lazy_entry const* url = url_seeds->list_at(i);
@ -1288,6 +1290,8 @@ namespace libtorrent
web_seed_entry ent(maybe_url_encode(url->string_value()) web_seed_entry ent(maybe_url_encode(url->string_value())
, web_seed_entry::url_seed); , web_seed_entry::url_seed);
if (m_multifile && ent.url[ent.url.size()-1] != '/') ent.url += '/'; if (m_multifile && ent.url[ent.url.size()-1] != '/') ent.url += '/';
if (unique.count(ent.url)) continue;
unique.insert(ent.url);
m_web_seeds.push_back(ent); m_web_seeds.push_back(ent);
} }
} }
@ -1301,12 +1305,16 @@ namespace libtorrent
} }
else if (http_seeds && http_seeds->type() == lazy_entry::list_t) else if (http_seeds && http_seeds->type() == lazy_entry::list_t)
{ {
// only add a URL once
std::set<std::string> unique;
for (int i = 0, end(http_seeds->list_size()); i < end; ++i) for (int i = 0, end(http_seeds->list_size()); i < end; ++i)
{ {
lazy_entry const* url = http_seeds->list_at(i); lazy_entry const* url = http_seeds->list_at(i);
if (url->type() != lazy_entry::string_t || url->string_length() == 0) continue; if (url->type() != lazy_entry::string_t || url->string_length() == 0) continue;
m_web_seeds.push_back(web_seed_entry(maybe_url_encode(url->string_value()) std::string u = maybe_url_encode(url->string_value());
, web_seed_entry::http_seed)); if (unique.count(u)) continue;
unique.insert(u);
m_web_seeds.push_back(web_seed_entry(u, web_seed_entry::http_seed));
} }
} }

View File

@ -52,7 +52,6 @@ TESTS = $(check_PROGRAMS)
EXTRA_DIST = Jamfile \ EXTRA_DIST = Jamfile \
test_torrents/base.torrent \ test_torrents/base.torrent \
test_torrents/empty_path.torrent \
test_torrents/parent_path.torrent \ test_torrents/parent_path.torrent \
test_torrents/hidden_parent_path.torrent \ test_torrents/hidden_parent_path.torrent \
test_torrents/single_multi_file.torrent \ test_torrents/single_multi_file.torrent \
@ -91,6 +90,8 @@ EXTRA_DIST = Jamfile \
test_torrents/invalid_root_hash2.torrent \ test_torrents/invalid_root_hash2.torrent \
test_torrents/root_hash.torrent \ test_torrents/root_hash.torrent \
test_torrents/invalid_file_size.torrent \ test_torrents/invalid_file_size.torrent \
test_torrents/empty_path_multi.torrent \
test_torrents/duplicate_web_seeds.torrent \
eztv.xml \ eztv.xml \
kat.xml \ kat.xml \
cb.xml \ cb.xml \

View File

@ -72,6 +72,7 @@ test_torrent_t test_torrents[] =
{ "url_seed_multi_space_nolist.torrent" }, { "url_seed_multi_space_nolist.torrent" },
{ "root_hash.torrent" }, { "root_hash.torrent" },
{ "empty_path_multi.torrent" }, { "empty_path_multi.torrent" },
{ "duplicate_web_seeds.torrent" },
{ "invalid_name3.torrent" }, { "invalid_name3.torrent" },
}; };
@ -382,12 +383,16 @@ int test_main()
else if (std::string(test_torrents[i].file) == "pad_file.torrent") else if (std::string(test_torrents[i].file) == "pad_file.torrent")
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_CHECK(ti->file_at(0).pad_file == false); TEST_EQUAL(ti->file_at(0).pad_file, false);
TEST_CHECK(ti->file_at(1).pad_file == true); TEST_EQUAL(ti->file_at(1).pad_file, true);
} }
else if (std::string(test_torrents[i].file) == "creation_date.torrent") else if (std::string(test_torrents[i].file) == "creation_date.torrent")
{ {
TEST_CHECK(*ti->creation_date() == 1234567); TEST_EQUAL(*ti->creation_date(), 1234567);
}
else if (std::string(test_torrents[i].file) == "duplicate_web_seeds.torrent")
{
TEST_EQUAL(ti->web_seeds().size(), 3);
} }
else if (std::string(test_torrents[i].file) == "no_creation_date.torrent") else if (std::string(test_torrents[i].file) == "no_creation_date.torrent")
{ {

View File

@ -0,0 +1 @@
d8:announce23:udp://test.com/announce10:created by10:libtorrent13:creation datei1359599503e4:infod6:lengthi425e4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW}ÜA4u,·¼‡e8:url-listl21:http://foobar.com/foo21:http://foobar.com/foo21:http://foobar.com/foo24:http://foobar.com/foobar21:http://foobar.com/foo21:http://foobar.com/foo21:http://foobar.com/foo21:http://foobar.com/baree