Skip to content

AttributeError in email._header_value_parser.get_address #134155

Description

@gabe-sherman

Bug report

Bug description:

During fuzzing of Python standard libraries, the following code snippet causes an AttributeError with the following message: AttributeError: 'InvalidHeaderDefect' object has no attribute 'all_defects'. This occurs in the all_defects function at line 140 in email/_header_value_parser.py.

import email._header_value_parser
email._header_value_parser.get_address("!an??:=m==fr2@[C")

Exception Trace

Traceback (most recent call last):
  File "rep.py", line 3, in <module>
    email._header_value_parser.get_address("!an??:=m==fr2@[C")
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 1988, in get_address
    token, value = get_group(value)
                   ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 1954, in get_group
    token, value = get_group_list(value)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 1926, in get_group_list
    token, value = get_mailbox_list(value)
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 1860, in get_mailbox_list
    token, value = get_mailbox(value)
                   ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 1822, in get_mailbox
    for x in token.all_defects):
             ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in all_defects
    return sum((x.all_defects for x in self), self.defects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in <genexpr>
    return sum((x.all_defects for x in self), self.defects)
                ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in all_defects
    return sum((x.all_defects for x in self), self.defects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in <genexpr>
    return sum((x.all_defects for x in self), self.defects)
                ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in all_defects
    return sum((x.all_defects for x in self), self.defects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/_header_value_parser.py", line 140, in <genexpr>
    return sum((x.all_defects for x in self), self.defects)
                ^^^^^^^^^^^^^
AttributeError: 'InvalidHeaderDefect' object has no attribute 'all_defects'

CPython versions tested on:

3.12, 3.11, 3.10, 3.9

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions