Skip to content

AttributeError in email._header_value_parser.get_address #134155

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

Closed
gabe-sherman opened this issue May 17, 2025 · 2 comments
Closed

AttributeError in email._header_value_parser.get_address #134155

gabe-sherman opened this issue May 17, 2025 · 2 comments
Labels
stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@gabe-sherman
Copy link

gabe-sherman commented May 17, 2025

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

@gabe-sherman gabe-sherman added the type-bug An unexpected behavior, bug, or error label May 17, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir topic-email labels May 17, 2025
@picnixz picnixz changed the title AttributeError in email._header_value_parser.get_address AttributeError in email._header_value_parser.get_address May 18, 2025
@bitdancer
Copy link
Member

This will be fixed by #134194.

bitdancer pushed a commit that referenced this issue Jun 5, 2025
…ss (#134194)

Append the defect to defects instead of to the parse tree.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 5, 2025
…_address (pythonGH-134194)

Append the defect to defects instead of to the parse tree.
(cherry picked from commit d9cad07)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 5, 2025
…_address (pythonGH-134194)

Append the defect to defects instead of to the parse tree.
(cherry picked from commit d9cad07)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
bitdancer pushed a commit that referenced this issue Jun 6, 2025
…t_address (GH-134194) (#135192)

gh-134155: fix AttributeError in email._header_value_parser.get_address (GH-134194)

Append the defect to defects instead of to the parse tree.
(cherry picked from commit d9cad07)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
bitdancer pushed a commit that referenced this issue Jun 6, 2025
…t_address (GH-134194) (#135191)

gh-134155: fix AttributeError in email._header_value_parser.get_address (GH-134194)

Append the defect to defects instead of to the parse tree.
(cherry picked from commit d9cad07)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@bitdancer
Copy link
Member

Thanks for fixing this, sergey-miryanov.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants