Skip to content

Commit ff4ca5c

Browse files
committed
Only allow 0-9 digits in MIME parameter section numbers
1 parent 958657b commit ff4ca5c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Lib/email/_header_value_parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,17 +2398,22 @@ def get_section(value):
23982398
The caller should already have dealt with leading CFWS.
23992399
24002400
"""
2401+
def is_allowed_digit(c):
2402+
# We don't use str.isdigit because only 0-9 are accepted, not
2403+
# super-script and other types of digits.
2404+
return c in {'0','1','2','3','4','5','6','7','8','9'}
2405+
24012406
section = Section()
24022407
if not value or value[0] != '*':
24032408
raise errors.HeaderParseError("Expected section but found {}".format(
24042409
value))
24052410
section.append(ValueTerminal('*', 'section-marker'))
24062411
value = value[1:]
2407-
if not value or not value[0].isdigit():
2412+
if not value or not is_allowed_digit(value[0]):
24082413
raise errors.HeaderParseError("Expected section number but "
24092414
"found {}".format(value))
24102415
digits = ''
2411-
while value and value[0].isdigit():
2416+
while value and is_allowed_digit(value[0]):
24122417
digits += value[0]
24132418
value = value[1:]
24142419
if digits[0] == '0' and digits != '0':

Lib/test/test_email/test__header_value_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,16 @@ def mime_parameters_as_value(self,
29822982
'r*=\'a\'"',
29832983
[('r', '"')],
29842984
[errors.InvalidHeaderDefect]*2),
2985+
2986+
# bpo-42946: Unicode super-script digits (and others) are not allowed
2987+
# as section numbers.
2988+
'non_allowed_digits': (
2989+
'foo*0=bar; foo*²=baz',
2990+
' foo="bar"',
2991+
'foo*0=bar; foo*²=baz',
2992+
[('foo', 'bar')],
2993+
[errors.InvalidHeaderDefect]),
2994+
29852995
}
29862996

29872997
@parameterize

0 commit comments

Comments
 (0)