]> granicus.if.org Git - python/commit
bpo-30835: email: Fix AttributeError when parsing invalid CTE (GH-13598)
authorAbhilash Raj <maxking@users.noreply.github.com>
Tue, 4 Jun 2019 18:00:47 +0000 (14:00 -0400)
committerBarry Warsaw <barry@python.org>
Tue, 4 Jun 2019 18:00:47 +0000 (11:00 -0700)
commitaa79707262f893428665ef45b5e879129abca4aa
treeaae19b8d8d91417c315cfe599236329eaa6b3bdc
parent46d88a113142b26c01c95c93846a89318ba87ffc
bpo-30835: email: Fix AttributeError when parsing invalid CTE (GH-13598)

* bpo-30835: email: Fix AttributeError when parsing invalid Content-Transfer-Encoding

Parsing an email containing a multipart Content-Type, along with a
Content-Transfer-Encoding containing an invalid (non-ASCII-decodable) byte
will fail. email.feedparser.FeedParser._parsegen() gets the header and
attempts to convert it to lowercase before comparing it with the accepted
encodings, but as the header contains an invalid byte, it's returned as a
Header object rather than a str.

Cast the Content-Transfer-Encoding header to a str to avoid this.

Found using the AFL fuzzer.

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Andrew Donnellan <andrew@donnellan.id.au>
* Add email and NEWS entry for the bugfix.
Lib/email/feedparser.py
Lib/test/test_email/test_email.py
Misc/NEWS.d/next/Library/2019-05-27-15-29-46.bpo-30835.3FoaWH.rst [new file with mode: 0644]