]> git.ipfire.org Git - thirdparty/patchwork.git/commit
parser: Handle even more exotically broken headers
authorDaniel Axtens <dja@axtens.net>
Mon, 19 Feb 2018 14:33:59 +0000 (01:33 +1100)
committerDaniel Axtens <daniel.axtens@canonical.com>
Tue, 6 Mar 2018 14:02:35 +0000 (01:02 +1100)
commit7079b3cf867ba86606f91890c523ce3343b03287
tree06328bf41f32180fa0df78b2a2663aa983af8f91
parentfec4f1317699a94da1340799b5a6b8237cf7df82
parser: Handle even more exotically broken headers

An archive of the Ubuntu kernel team mailing list contains a
fascinating email that causes the following parse error:

email.errors.HeaderParseError: header value appears to contain an embedded header:
  '4Mf^tnii7k\\_EnR5aobBm6Di[DZ9@AX1wJ"okBdX-UoJ>:SRn]c6DDU"qUIwfs98vF>...

The broken bit seem related to a UTF-8 quoted-printable encoded
section and to be from an internal attempt to break it over multiple
lines: here's a snippet from the error message:
    '\n\t=?utf-8?q?Tnf?=\n'
but interesting the header itself does not contain the new lines, so
clearly something quite weird is happening behind the scenes!

This only throws on header.encode(): it actually makes it through
sanitise_header and into find_headers before throwing the assertion.

So, try to encode in sanitize_header as a final step.

Also, fix a hilarious* python bug that this exposes: whitespace-only
headers cause an index error!

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/parser.py
patchwork/tests/fuzztests/x-face.mbox [new file with mode: 0644]
patchwork/tests/test_parser.py