mirror of https://github.com/aria2/aria2
2008-08-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Removed max chunk size check. This change fixes BUG#2040169 * src/ChunkedDecoder.cc * src/ChunkedDecoder.h * test/ChunkedDecoderTest.ccpull/1/head
parent
d64c8e75f6
commit
49c4f82561
|
@ -49,7 +49,7 @@ ChunkedDecoder::~ChunkedDecoder() {}
|
||||||
|
|
||||||
void ChunkedDecoder::init() {}
|
void ChunkedDecoder::init() {}
|
||||||
|
|
||||||
static bool readChunkSize(size_t& chunkSize, std::string& in)
|
static bool readChunkSize(uint64_t& chunkSize, std::string& in)
|
||||||
{
|
{
|
||||||
std::string::size_type crlfPos = in.find(A2STR::CRLF);
|
std::string::size_type crlfPos = in.find(A2STR::CRLF);
|
||||||
if(crlfPos == std::string::npos) {
|
if(crlfPos == std::string::npos) {
|
||||||
|
@ -59,14 +59,14 @@ static bool readChunkSize(size_t& chunkSize, std::string& in)
|
||||||
if(extPos == std::string::npos || crlfPos < extPos) {
|
if(extPos == std::string::npos || crlfPos < extPos) {
|
||||||
extPos = crlfPos;
|
extPos = crlfPos;
|
||||||
}
|
}
|
||||||
chunkSize = Util::parseUInt(in.substr(0, extPos), 16);
|
chunkSize = Util::parseULLInt(in.substr(0, extPos), 16);
|
||||||
in.erase(0, crlfPos+2);
|
in.erase(0, crlfPos+2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool readData(std::string& out, size_t& chunkSize, std::string& in)
|
static bool readData(std::string& out, uint64_t& chunkSize, std::string& in)
|
||||||
{
|
{
|
||||||
size_t readlen = std::min(chunkSize, in.size());
|
uint64_t readlen = std::min(chunkSize, static_cast<uint64_t>(in.size()));
|
||||||
out.append(in.begin(), in.begin()+readlen);
|
out.append(in.begin(), in.begin()+readlen);
|
||||||
in.erase(0, readlen);
|
in.erase(0, readlen);
|
||||||
chunkSize -= readlen;
|
chunkSize -= readlen;
|
||||||
|
@ -94,10 +94,6 @@ std::string ChunkedDecoder::decode(const unsigned char* inbuf, size_t inlen)
|
||||||
_state = STREAM_END;
|
_state = STREAM_END;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if(_chunkSize > MAX_CHUNK_SIZE) {
|
|
||||||
throw DlAbortEx
|
|
||||||
(StringFormat(EX_TOO_LARGE_CHUNK, _chunkSize).str());
|
|
||||||
}
|
|
||||||
_state = READ_DATA;
|
_state = READ_DATA;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -49,12 +49,10 @@ private:
|
||||||
|
|
||||||
std::string _buf;
|
std::string _buf;
|
||||||
|
|
||||||
size_t _chunkSize;
|
uint64_t _chunkSize;
|
||||||
|
|
||||||
STATE _state;
|
STATE _state;
|
||||||
|
|
||||||
static const size_t MAX_CHUNK_SIZE = 1024*1024;
|
|
||||||
|
|
||||||
static const std::string NAME;
|
static const std::string NAME;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -110,16 +110,24 @@ void ChunkedDecoderTest::testDecode()
|
||||||
|
|
||||||
void ChunkedDecoderTest::testDecode_tooLargeChunkSize()
|
void ChunkedDecoderTest::testDecode_tooLargeChunkSize()
|
||||||
{
|
{
|
||||||
// Feed chunkSize == ChunkedDecoder::MAX_CHUNK_SIZE + 1 == 0x100001.
|
// chunkSize should be under 2^64-1
|
||||||
std::basic_string<unsigned char> msg =
|
{
|
||||||
reinterpret_cast<const unsigned char*>("100001\r\n");
|
std::basic_string<unsigned char> msg =
|
||||||
|
reinterpret_cast<const unsigned char*>("ffffffffffffffff\r\n");
|
||||||
ChunkedDecoder decoder;
|
ChunkedDecoder decoder;
|
||||||
try {
|
|
||||||
decoder.decode(msg.c_str(), msg.size());
|
decoder.decode(msg.c_str(), msg.size());
|
||||||
CPPUNIT_FAIL("exception must be thrown.");
|
}
|
||||||
} catch(DlAbortEx& e) {
|
// chunkSize 2^64 causes error
|
||||||
// success
|
{
|
||||||
|
std::basic_string<unsigned char> msg =
|
||||||
|
reinterpret_cast<const unsigned char*>("10000000000000000\r\n");
|
||||||
|
ChunkedDecoder decoder;
|
||||||
|
try {
|
||||||
|
decoder.decode(msg.c_str(), msg.size());
|
||||||
|
CPPUNIT_FAIL("exception must be thrown.");
|
||||||
|
} catch(DlAbortEx& e) {
|
||||||
|
// success
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue