introduce safety limit on total number of items in bencoded trees in lazy_bdecode. Document lazy_bdecode and its error codes. Make dump_torrent able to change the decoding limits
This commit is contained in:
@@ -79,7 +79,7 @@ namespace libtorrent
|
||||
|
||||
// return 0 = success
|
||||
int lazy_bdecode(char const* start, char const* end, lazy_entry& ret
|
||||
, error_code& ec, int* error_pos, int depth_limit)
|
||||
, error_code& ec, int* error_pos, int depth_limit, int item_limit)
|
||||
{
|
||||
char const* const orig_start = start;
|
||||
ret.clear();
|
||||
@@ -142,6 +142,9 @@ namespace libtorrent
|
||||
default: break;
|
||||
}
|
||||
|
||||
--item_limit;
|
||||
if (item_limit <= 0) TORRENT_FAIL_BDECODE(errors::limit_exceeded);
|
||||
|
||||
top = stack.back();
|
||||
switch (t)
|
||||
{
|
||||
@@ -177,8 +180,10 @@ namespace libtorrent
|
||||
continue;
|
||||
}
|
||||
}
|
||||
printf("lazy_bdecode item_limit: %d\n", item_limit);
|
||||
return 0;
|
||||
}
|
||||
printf("lazy_bdecode item_limit: %d\n", item_limit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -505,7 +510,7 @@ namespace libtorrent
|
||||
case lazy_entry::list_t:
|
||||
{
|
||||
ret += '[';
|
||||
bool one_liner = line_longer_than(e, 130) != -1 || single_line;
|
||||
bool one_liner = line_longer_than(e, 200) != -1 || single_line;
|
||||
|
||||
if (!one_liner) ret += indent_str + 1;
|
||||
for (int i = 0; i < e.list_size(); ++i)
|
||||
@@ -521,7 +526,7 @@ namespace libtorrent
|
||||
case lazy_entry::dict_t:
|
||||
{
|
||||
ret += "{";
|
||||
bool one_liner = line_longer_than(e, 130) != -1 || single_line;
|
||||
bool one_liner = line_longer_than(e, 200) != -1 || single_line;
|
||||
|
||||
if (!one_liner) ret += indent_str+1;
|
||||
for (int i = 0; i < e.dict_size(); ++i)
|
||||
|
Reference in New Issue
Block a user