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.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-08-07 14:06:03 +00:00
parent d64c8e75f6
commit 49c4f82561
3 changed files with 22 additions and 20 deletions

View File

@ -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<uint64_t>(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 {

View File

@ -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:

View File

@ -110,10 +110,17 @@ void ChunkedDecoderTest::testDecode()
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");
reinterpret_cast<const unsigned char*>("ffffffffffffffff\r\n");
ChunkedDecoder decoder;
decoder.decode(msg.c_str(), msg.size());
}
// chunkSize 2^64 causes error
{
std::basic_string<unsigned char> msg =
reinterpret_cast<const unsigned char*>("10000000000000000\r\n");
ChunkedDecoder decoder;
try {
decoder.decode(msg.c_str(), msg.size());
@ -121,6 +128,7 @@ void ChunkedDecoderTest::testDecode_tooLargeChunkSize()
} catch(DlAbortEx& e) {
// success
}
}
}
void ChunkedDecoderTest::testDecode_chunkSizeMismatch()