make bdecoder more robust when encountering errors (leave the resulting tree consistent)

This commit is contained in:
Arvid Norberg
2012-02-10 04:19:11 +00:00
parent be339c244f
commit c384d00dbf
3 changed files with 32 additions and 1 deletions

View File

@@ -51,6 +51,12 @@ namespace libtorrent
#define TORRENT_FAIL_BDECODE(code) \
{ \
ec = code; \
while (!stack.empty()) { \
top = stack.back(); \
fprintf(stderr, "top->type: %d\n", top->type()); \
if (top->type() == lazy_entry::dict_t || top->type() == lazy_entry::list_t) top->pop(); \
stack.pop_back(); \
} \
if (error_pos) *error_pos = start - orig_start; \
return -1; \
}
@@ -176,7 +182,11 @@ namespace libtorrent
}
default:
{
if (!is_digit(t)) TORRENT_FAIL_BDECODE(errors::expected_value);
if (!is_digit(t))
{
int a = 0;
TORRENT_FAIL_BDECODE(errors::expected_value);
}
boost::int64_t len = t - '0';
start = parse_int(start, end, ':', len);
@@ -234,6 +244,11 @@ namespace libtorrent
return &ret.val;
}
void lazy_entry::pop()
{
if (m_size > 0) --m_size;
}
namespace
{
// the number of decimal digits needed