diff --git a/ChangeLog b/ChangeLog index 3f8e0e8e..61e43528 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-05-06 Tatsuhiro Tsujikawa + + Avoid std::bad_alloc for negative bencode string length. + * src/bencode.cc + 2009-05-06 Tatsuhiro Tsujikawa Supported segmented downloading with chunked transfer encoding and diff --git a/src/bencode.cc b/src/bencode.cc index 9b43261e..0fb39eb7 100644 --- a/src/bencode.cc +++ b/src/bencode.cc @@ -57,9 +57,9 @@ static void checkdelim(std::istream& ss, const char delim = ':') static std::string decoderawstring(std::istream& ss) { - size_t length; + int length; ss >> length; - if(!ss) { + if(!ss || length < 0) { throw RecoverableException("A positive integer expected but none found."); } // TODO check length, it must be less than or equal to INT_MAX