mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
46d88a1131
commit
aa79707262
3 changed files with 13 additions and 1 deletions
|
@ -1466,6 +1466,15 @@ Blah blah blah
|
|||
g.flatten(msg)
|
||||
self.assertEqual(b.getvalue(), source + b'>From R\xc3\xb6lli\n')
|
||||
|
||||
def test_mutltipart_with_bad_bytes_in_cte(self):
|
||||
# bpo30835
|
||||
source = textwrap.dedent("""\
|
||||
From: aperson@example.com
|
||||
Content-Type: multipart/mixed; boundary="1"
|
||||
Content-Transfer-Encoding: \xc8
|
||||
""").encode('utf-8')
|
||||
msg = email.message_from_bytes(source)
|
||||
|
||||
|
||||
# Test the basic MIMEAudio class
|
||||
class TestMIMEAudio(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue