Skip to content

UnstructuredHeader drops encoded-word Base64 padding defects #158780

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: BaseHeader documentation in email.headerregistry: "Defects should be added to the list instead. The standard header parsers register defects for RFC compliance issues, for obsolete RFC syntax, and for unrecoverable parsing errors."

Expected: The Subject header's defects includes InvalidBase64PaddingDefect.

Actual: The parser's all_defects includes InvalidBase64PaddingDefect, but the Subject header's defects does not.

from email.headerregistry import HeaderRegistry, UnstructuredHeader
from email.errors import InvalidBase64PaddingDefect

value = '=?utf-8?b?YQ?='
if not value.isascii() or '\r' in value or '\n' in value:
    print('REFUTATION REJECTED: input is not unfolded ASCII')
else:
    expected = any(isinstance(d, InvalidBase64PaddingDefect)
                   for d in UnstructuredHeader.value_parser(value).all_defects)
    actual = any(isinstance(d, InvalidBase64PaddingDefect)
                 for d in HeaderRegistry()('Subject', value).defects)
    if expected and not actual:
        print('REFUTATION CONFIRMED:', repr(value),
              'actual:', actual, 'expected:', expected)
    else:
        print('REFUTATION REJECTED: parser prerequisite absent or defect preserved',
              repr(value), 'actual:', actual, 'expected:', expected)

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library email.headerregistry:

REFUTATION CONFIRMED: '=?utf-8?b?YQ?=' actual: False expected: True

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/email.headerregistry-20261003-021509-c2

CPython versions tested on:

3.14

Operating systems tested on:

Windows

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions