]> git.ipfire.org Git - thirdparty/squid.git/commit - src/adaptation/icap/ModXact.cc
Fix incremental parsing of chunked quoted extensions (#310)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Mon, 18 Mar 2019 17:48:21 +0000 (17:48 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 18 Mar 2019 17:48:25 +0000 (17:48 +0000)
commit417da4006cf5c97d44e74431b816fc58fec9e270
tree7878f240d264041f859de0b46de06e1580d6e849
parent29a0bb6acde0096292947d9c46966205f7d304c7
Fix incremental parsing of chunked quoted extensions (#310)

Before this change, incremental parsing of quoted chunked extensions
was broken for two reasons:

* Http::One::Parser::skipLineTerminator() unexpectedly threw after
  partially received quoted chunk extension value.

* When Http::One::Tokenizer was unable to parse a quoted extension,
  it incorrectly restored the input buffer to the beginning of the
  extension value (instead of the extension itself), thus making
  further incremental parsing iterations impossible.

IMO, the reason for this problem was that Http::One::Tokenizer::qdText()
could not distinguish two cases (returning false in both):

* the end of the quoted string not yet reached

* an input error, e.g., wrong/unexpected character

A possible approach could be to improve Http::One::Tokenizer, making it
aware about "needs more data" state.  However, to be acceptable,
these improvements should be done in the base Parser::Tokenizer
class instead. These changes seem to be non-trivial and could be
done separately and later.

Another approach, used here, is to simplify the complex and error-prone
chunked extensions parsing algorithm, fixing incremental parsing bugs
and still parse incrementally in almost all cases. The performance
regression could be expected only in relatively rare cases of partially
received or malformed extensions.

Also:
* fixed parsing of partial use-original-body extension values
* do not treat an invalid use-original-body as an unknown extension
* optimization: parse use-original-body extension only in ICAP context
  (i.e., where it is expected)
* improvement: added a new API to TeChunkedParser to specify known
  chunked extensions list
18 files changed:
src/adaptation/icap/ModXact.cc
src/adaptation/icap/ModXact.h
src/http/one/Parser.cc
src/http/one/Parser.h
src/http/one/RequestParser.cc
src/http/one/RequestParser.h
src/http/one/ResponseParser.cc
src/http/one/ResponseParser.h
src/http/one/TeChunkedParser.cc
src/http/one/TeChunkedParser.h
src/http/one/Tokenizer.cc
src/http/one/Tokenizer.h
src/http/one/forward.h
src/parser/BinaryTokenizer.h
src/parser/Makefile.am
src/parser/Tokenizer.cc
src/parser/Tokenizer.h
src/parser/forward.h [new file with mode: 0644]