Ver código fonte

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
Tatsuhiro Tsujikawa 17 anos atrás
pai
commit
49c4f82561
3 arquivos alterados com 22 adições e 20 exclusões
  1. 4 8
      src/ChunkedDecoder.cc
  2. 1 3
      src/ChunkedDecoder.h
  3. 17 9
      test/ChunkedDecoderTest.cc

+ 4 - 8
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<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 {

+ 1 - 3
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:

+ 17 - 9
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<unsigned char> msg =
-    reinterpret_cast<const unsigned char*>("100001\r\n");
-
-  ChunkedDecoder decoder;
-  try {
+  // chunkSize should be under 2^64-1
+  {
+    std::basic_string<unsigned char> msg =
+      reinterpret_cast<const unsigned char*>("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<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
+    }
   }
 }