bpo-37764: Fix infinite loop when parsing unstructured email headers. (GH-15239)

Fixes a case in which email._header_value_parser.get_unstructured hangs the system for some invalid headers. This covers the cases in which the header contains either:
- a case without trailing whitespace
- an invalid encoded word

https://bugs.python.org/issue37764

This fix should also be backported to 3.7 and 3.8


https://bugs.python.org/issue37764
This commit is contained in:
Ashwin Ramaswami 2019-08-31 10:25:35 -05:00 committed by Miss Islington (bot)
parent daa82d019c
commit c5b242f87f
5 changed files with 55 additions and 3 deletions

View file

@ -383,6 +383,22 @@ class TestParser(TestParserMixin, TestEmailBase):
[errors.InvalidHeaderDefect],
'')
def test_get_unstructured_without_trailing_whitespace_hang_case(self):
self._test_get_x(self._get_unst,
'=?utf-8?q?somevalue?=aa',
'somevalueaa',
'somevalueaa',
[errors.InvalidHeaderDefect],
'')
def test_get_unstructured_invalid_ew(self):
self._test_get_x(self._get_unst,
'=?utf-8?q?=somevalue?=',
'=?utf-8?q?=somevalue?=',
'=?utf-8?q?=somevalue?=',
[],
'')
# get_qp_ctext
def test_get_qp_ctext_only(self):