From: Alex Rousskov Date: Wed, 21 Oct 2015 11:59:13 +0000 (-0700) Subject: Fixed chunked parsing by mimicking psChunkEnd state removed in trunk r14108. X-Git-Tag: SQUID_4_0_2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8103fa6626dacffe936537354373c495e7de0696;p=thirdparty%2Fsquid.git Fixed chunked parsing by mimicking psChunkEnd state removed in trunk r14108. ... 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. --- diff --git a/src/http/one/TeChunkedParser.cc b/src/http/one/TeChunkedParser.cc index 6590cb7e58..5abee24306 100644 --- a/src/http/one/TeChunkedParser.cc +++ b/src/http/one/TeChunkedParser.cc @@ -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);