Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.8] bpo-38708: email: Fix a potential IndexError when parsing Message-ID (GH-17504) #17515

Merged
merged 1 commit into from Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/email/_header_value_parser.py
Expand Up @@ -2042,7 +2042,7 @@ def get_msg_id(value):
no-fold-literal = "[" *dtext "]"
"""
msg_id = MsgID()
if value[0] in CFWS_LEADER:
if value and value[0] in CFWS_LEADER:
token, value = get_cfws(value)
msg_id.append(token)
if not value or value[0] != '<':
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Expand Up @@ -2583,6 +2583,11 @@ def test_invalid_content_transfer_encoding(self):

# get_msg_id

def test_get_msg_id_empty(self):
# bpo-38708: Test that HeaderParseError is raised and not IndexError.
with self.assertRaises(errors.HeaderParseError):
parser.get_msg_id('')

def test_get_msg_id_valid(self):
msg_id = self._test_get_x(
parser.get_msg_id,
Expand Down Expand Up @@ -2660,6 +2665,7 @@ def test_get_msg_id_no_angle_end(self):
self.assertEqual(msg_id.token_type, 'msg-id')



@parameterize
class Test_parse_mime_parameters(TestParserMixin, TestEmailBase):

Expand Down
@@ -0,0 +1 @@
Fix a potential IndexError in email parser when parsing an empty msg-id.