Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ def decode_params(params):
for name, continuations in rfc2231_params.items():
value = []
extended = False
if len(continuations) > 1 and any(num is None for num, *_ in continuations):
msg = f"Invalid RFC 2231 parameter continuation for '{name}'"
raise ValueError(msg)
# Sort by number
continuations.sort()
# And now append all values in numerical order, converting
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -5757,6 +5757,16 @@ def test_should_not_hang_on_invalid_ew_messages(self):
with self.subTest(m=m):
msg = email.message_from_string(m)

def test_rfc2231_invalid_parameter_continuation(self):
# gh-125648: should raise a ValueError for invalid parameter continuation
m = """\
Content-Type: application/x-foo;
\tname*0="foo";
\tname*="bar"
"""
msg = email.message_from_string(m)
with self.assertRaisesRegex(ValueError, "Invalid RFC 2231 parameter continuation for 'name'"):
msg.get_params()

# Tests to ensure that signed parts of an email are completely preserved, as
# required by RFC1847 section 2.1. Note that these are incomplete, because the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use a more descriptive error message when encountering invalid parameter
continuations in :meth:`email.message.Message.get_params`.
Loading