Skip to content

uu codec decoder treats any line starting with "begin" as the header #161092

Closed

Description

@gpshead

Bug report

Bug description:

The uu codec's decoder takes the first line whose first five bytes are begin as the uuencode header, without checking that an octal mode follows. A line of leading text such as "beginning of the report", a bare begin or a begin-base64 header therefore starts the data, so the codec either decodes the wrong block or raises binascii.Error on well-formed input.

import codecs, email
text = b"beginning of the report\n#0V%T\n \nend\nbegin 666 pet.txt\n#9&]G\n \nend\n"
print(codecs.decode(text, "uu"))  # b'Cat'
msg = email.message_from_bytes(b"Content-Transfer-Encoding: x-uuencode\n\n" + text)
print(msg.get_payload(decode=True))  # b'dog'
codecs.decode(b"beginning with version 2\n" + codecs.encode(b"hello", "uu"), "uu")
# binascii.Error: Illegal char

Expected b'dog' from both, as email.message._decode_uu() and the removed uu.decode() skip lines that are not begin <octal mode>. The prefix test came over unchanged from Python 2 when the codec was restored in 3.2.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 1, 2026
  3. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions