Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
Closed
Description
During fuzzing of Python standard libraries, the following code snippet causes anUnboundLocalError
with the following message:UnboundLocalError: cannot access local variable 'pos' where it is not associated with a value'
. This occurs in the_get_ptext_to_endchars
function at line 1035 inemail/_header_value_parser.py
.
importemail._header_value_parseremail._header_value_parser.parse_message_id("<T@[")
Exception Trace
Traceback (most recent call last): File"/usr/lib/python3.12/email/_header_value_parser.py", line2118, inget_msg_id token, value= get_dot_atom_text(value)^^^^^^^^^^^^^^^^^^^^^^^^ File"/usr/lib/python3.12/email/_header_value_parser.py", line1344, inget_dot_atom_textraise 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"rep.py", line2, in<module> email._header_value_parser.parse_message_id("<T@[") File"/usr/lib/python3.12/email/_header_value_parser.py", line2149, inparse_message_id token, value= get_msg_id(value)^^^^^^^^^^^^^^^^^ File"/usr/lib/python3.12/email/_header_value_parser.py", line2121, inget_msg_id token, value= get_no_fold_literal(value)^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/usr/lib/python3.12/email/_header_value_parser.py", line2066, inget_no_fold_literal token, value= get_dtext(value)^^^^^^^^^^^^^^^^ File"/usr/lib/python3.12/email/_header_value_parser.py", line1557, inget_dtext ptext, value, had_qp= _get_ptext_to_endchars(value,'[]')^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/usr/lib/python3.12/email/_header_value_parser.py", line1033, in_get_ptext_to_endchars pos= pos+1^^^UnboundLocalError:cannot access local variable 'pos' where it is not associated with a value
CPython versions tested on:
3.12, 3.11, 3.10, 3.9
Operating systems tested on:
Linux
Linked PRs
- gh-134155: fix AttributeError in email._header_value_parser.get_address #134194
- gh-134152: Fix UnboundLocalError in email._header_value_parser _get_ptext_to_endchars #134233
- [3.13] gh-134152: Fix UnboundLocalError in email._header_value_parser _get_ptext_to_endchars (GH-134233) #134677
- [3.14] gh-134152: Fix UnboundLocalError in email._header_value_parser _get_ptext_to_endchars (GH-134233) #134678