New submission from bpoaugust <sebbaz+...@gmail.com>:
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 ---------- components: email messages: 410972 nosy: barry, bpoaugust, r.david.murray priority: normal severity: normal status: open title: MessageID parser can crash with IndexError: string index out of range type: crash _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46435> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com