Skip to content

AttributeError in email._header_value_parser.get_address #134155

Closed
@gabe-sherman

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

changed the title [-]`AttributeError` in email._header_value_parser.get_address[/-] [+]`AttributeError` in `email._header_value_parser.get_address`[/+] on May 18, 2025
bitdancer

bitdancer commented on May 19, 2025

@bitdancer
Member

This will be fixed by #134194.

added a commit that references this issue on Jun 5, 2025

gh-134155: fix AttributeError in email._header_value_parser.get_addre…

d9cad07
added a commit that references this issue on Jun 5, 2025

pythongh-134155: fix AttributeError in email._header_value_parser.get…

added 2 commits that reference this issue on Jun 6, 2025

[3.13] gh-134155: fix AttributeError in email._header_value_parser.ge…

58b9581

[3.14] gh-134155: fix AttributeError in email._header_value_parser.ge…

3faf00e

3 remaining items

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

    stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      `AttributeError` in `email._header_value_parser.get_address` · Issue #134155 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant