This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bpoaugust
Recipients barry, bpoaugust, r.david.murray
Date 2022-01-19.17:01:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642611696.19.0.00941032029995.issue46435@roundup.psfhosted.org>
In-reply-to
Content
The Message-ID parser can crash on truncated input.

For example:

import email.policy
message=email.message_from_string("Message-id: <A@", policy=email.policy.default)
message['Message-id']

results in:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 2095, in get_msg_id
    token, value = get_dot_atom_text(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 1334, in get_dot_atom_text
    raise errors.HeaderParseError("expected atom at a start of "
email.errors.HeaderParseError: expected atom at a start of dot-atom-text but found ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 2098, in get_msg_id
    token, value = get_no_fold_literal(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 2035, in get_no_fold_literal
    raise errors.HeaderParseError(
email.errors.HeaderParseError: expected no-fold-literal but found ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/private/var/sebb/git/pmfoal/local/testm1.py", line 23, in <module>
    message['Message-id']
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/message.py", line 391, in __getitem__
    return self.get(name)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/message.py", line 471, in get
    return self.policy.header_fetch_parse(k, v)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/policy.py", line 163, in header_fetch_parse
    return self.header_factory(name, value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py", line 604, in __call__
    return self[name](name, value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py", line 192, in __new__
    cls.parse(value, kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py", line 532, in parse
    kwds['parse_tree'] = parse_tree = cls.value_parser(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 2126, in parse_message_id
    token, value = get_msg_id(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 2101, in get_msg_id
    token, value = get_domain(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py", line 1604, in get_domain
    if value[0] in CFWS_LEADER:
IndexError: string index out of range
History
Date User Action Args
2022-01-19 17:01:36bpoaugustsetrecipients: + bpoaugust, barry, r.david.murray
2022-01-19 17:01:36bpoaugustsetmessageid: <1642611696.19.0.00941032029995.issue46435@roundup.psfhosted.org>
2022-01-19 17:01:36bpoaugustlinkissue46435 messages
2022-01-19 17:01:35bpoaugustcreate