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

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