summaryrefslogtreecommitdiff
path: root/Lib/email
diff options
context:
space:
mode:
authorAbhilash Raj <maxking@users.noreply.github.com>2019-06-04 14:00:47 -0400
committerBarry Warsaw <barry@python.org>2019-06-04 11:00:47 -0700
commitaa79707262f893428665ef45b5e879129abca4aa (patch)
treeaae19b8d8d91417c315cfe599236329eaa6b3bdc /Lib/email
parent46d88a113142b26c01c95c93846a89318ba87ffc (diff)
downloadcpython-git-aa79707262f893428665ef45b5e879129abca4aa.tar.gz
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.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/feedparser.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index 7c07ca8645..97d3f5144d 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -320,7 +320,7 @@ class FeedParser:
self._cur.set_payload(EMPTYSTRING.join(lines))
return
# Make sure a valid content type was specified per RFC 2045:6.4.
- if (self._cur.get('content-transfer-encoding', '8bit').lower()
+ if (str(self._cur.get('content-transfer-encoding', '8bit')).lower()
not in ('7bit', '8bit', 'binary')):
defect = errors.InvalidMultipartContentTransferEncodingDefect()
self.policy.handle_defect(self._cur, defect)