Skip to content

Commit a4a994b

Browse files
maxkingwarsaw
authored andcommitted
bpo-37461: Fix infinite loop in parsing of specially crafted email headers (GH-14794)
* bpo-37461: Fix infinite loop in parsing of specially crafted email headers. Some crafted email header would cause the get_parameter method to run in an infinite loop causing a DoS attack surface when parsing those headers. This patch fixes that by making sure the DQUOTE character is handled to prevent going into an infinite loop.
1 parent 82494aa commit a4a994b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Lib/email/_header_value_parser.py

+3
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,9 @@ def get_parameter(value):
24962496
while value:
24972497
if value[0] in WSP:
24982498
token, value = get_fws(value)
2499+
elif value[0] == '"':
2500+
token = ValueTerminal('"', 'DQUOTE')
2501+
value = value[1:]
24992502
else:
25002503
token, value = get_qcontent(value)
25012504
v.append(token)

Lib/test/test_email/test__header_value_parser.py

+7
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,13 @@ def mime_parameters_as_value(self,
27102710
# Defects are apparent missing *0*, and two 'out of sequence'.
27112711
[errors.InvalidHeaderDefect]*3),
27122712

2713+
# bpo-37461: Check that we don't go into an infinite loop.
2714+
'extra_dquote': (
2715+
'r*="\'a\'\\"',
2716+
' r="\\""',
2717+
'r*=\'a\'"',
2718+
[('r', '"')],
2719+
[errors.InvalidHeaderDefect]*2),
27132720
}
27142721

27152722
@parameterize
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an inifite loop when parsing specially crafted email headers. Patch by
2+
Abhilash Raj.

0 commit comments

Comments
 (0)