diff --git a/src/ChunkedDecoder.cc b/src/ChunkedDecoder.cc index 9ec6872a..1404348b 100644 --- a/src/ChunkedDecoder.cc +++ b/src/ChunkedDecoder.cc @@ -49,7 +49,7 @@ ChunkedDecoder::~ChunkedDecoder() {} 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); 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) { extPos = crlfPos; } - chunkSize = Util::parseUInt(in.substr(0, extPos), 16); + chunkSize = Util::parseULLInt(in.substr(0, extPos), 16); in.erase(0, crlfPos+2); 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(in.size())); out.append(in.begin(), in.begin()+readlen); in.erase(0, readlen); chunkSize -= readlen; @@ -94,10 +94,6 @@ std::string ChunkedDecoder::decode(const unsigned char* inbuf, size_t inlen) _state = STREAM_END; break; } else { - if(_chunkSize > MAX_CHUNK_SIZE) { - throw DlAbortEx - (StringFormat(EX_TOO_LARGE_CHUNK, _chunkSize).str()); - } _state = READ_DATA; } } else { diff --git a/src/ChunkedDecoder.h b/src/ChunkedDecoder.h index e5b58edb..6aa5d1f2 100644 --- a/src/ChunkedDecoder.h +++ b/src/ChunkedDecoder.h @@ -49,12 +49,10 @@ private: std::string _buf; - size_t _chunkSize; + uint64_t _chunkSize; STATE _state; - static const size_t MAX_CHUNK_SIZE = 1024*1024; - static const std::string NAME; public: diff --git a/test/ChunkedDecoderTest.cc b/test/ChunkedDecoderTest.cc index 84234abe..dd1b1c2b 100644 --- a/test/ChunkedDecoderTest.cc +++ b/test/ChunkedDecoderTest.cc @@ -110,16 +110,24 @@ void ChunkedDecoderTest::testDecode() void ChunkedDecoderTest::testDecode_tooLargeChunkSize() { - // Feed chunkSize == ChunkedDecoder::MAX_CHUNK_SIZE + 1 == 0x100001. - std::basic_string msg = - reinterpret_cast("100001\r\n"); - - ChunkedDecoder decoder; - try { + // chunkSize should be under 2^64-1 + { + std::basic_string msg = + reinterpret_cast("ffffffffffffffff\r\n"); + ChunkedDecoder decoder; decoder.decode(msg.c_str(), msg.size()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(DlAbortEx& e) { - // success + } + // chunkSize 2^64 causes error + { + std::basic_string msg = + reinterpret_cast("10000000000000000\r\n"); + ChunkedDecoder decoder; + try { + decoder.decode(msg.c_str(), msg.size()); + CPPUNIT_FAIL("exception must be thrown."); + } catch(DlAbortEx& e) { + // success + } } }