]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed chunked parsing by mimicking psChunkEnd state removed in trunk r14108.
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 21 Oct 2015 11:59:13 +0000 (04:59 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 21 Oct 2015 11:59:13 +0000 (04:59 -0700)
... or, more precisely, in r13994.1.4 (parser-ng-chunked: re-write parse
sequence using ParseState stages instead of Step method pointers). Before
parser-ng-chunked, reaching zero theLeftBodySize would switch the chunk
parser to the psChunkEnd state. It was possible to pause parsing in that
state and resume it when more data becomes available, including the CRLF that
follows the chunk data. After parser-ng-chunked, the state remains
HTTP_PARSE_CHUNK which implies positive theLeftBodySize.

src/http/one/TeChunkedParser.cc

index 6590cb7e58744d07b19ae93b127e9ebf58c5ad8b..5abee24306121f2797b89f521d376cfcc5ecc438 100644 (file)
@@ -164,19 +164,19 @@ Http::One::TeChunkedParser::parseChunkExtension(Http1::Tokenizer &tok, bool skip
 bool
 Http::One::TeChunkedParser::parseChunkBody(Http1::Tokenizer &tok)
 {
-    Must(theLeftBodySize > 0); // Should, really
+    if (theLeftBodySize > 0) {
+        buf_ = tok.remaining(); // sync buffers before buf_ use
 
-    buf_ = tok.remaining(); // sync buffers before buf_ use
+        // TODO fix type mismatches and casting for these
+        const size_t availSize = min(theLeftBodySize, (uint64_t)buf_.length());
+        const size_t safeSize = min(availSize, (size_t)theOut->potentialSpaceSize());
 
-    // TODO fix type mismatches and casting for these
-    const size_t availSize = min(theLeftBodySize, (uint64_t)buf_.length());
-    const size_t safeSize = min(availSize, (size_t)theOut->potentialSpaceSize());
+        theOut->append(buf_.rawContent(), safeSize);
+        buf_.consume(safeSize);
+        theLeftBodySize -= safeSize;
 
-    theOut->append(buf_.rawContent(), safeSize);
-    buf_.consume(safeSize);
-    theLeftBodySize -= safeSize;
-
-    tok.reset(buf_); // sync buffers after consume()
+        tok.reset(buf_); // sync buffers after consume()
+    }
 
     if (theLeftBodySize == 0)
         return parseChunkEnd(tok);