Skip to content

gh-153679: Raise ZipImportError for an invalid UTF-8 file name in zipimport#153680

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:zipimport-utf8-name-decode
Open

gh-153679: Raise ZipImportError for an invalid UTF-8 file name in zipimport#153680
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:zipimport-utf8-name-decode

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

zipimport.zipimporter() is documented to raise ZipImportError for an
invalid archive, but _read_directory() leaked a raw UnicodeDecodeError
when a central directory entry set the UTF-8 file name flag (0x800) but
stored bytes that are not valid UTF-8: the UTF-8 branch called name.decode()
unguarded, while the sibling non-UTF-8 branch already handles
UnicodeDecodeError.

Guard the UTF-8 decode and raise ZipImportError, matching the documented
contract and every other corruption path in the function.

…in zipimport

zipimport.zipimporter() is documented to raise ZipImportError for an invalid
archive, but _read_directory() leaked a raw UnicodeDecodeError when a central
directory entry set the UTF-8 file name flag (0x800) but stored bytes that are
not valid UTF-8: the UTF-8 branch called name.decode() unguarded, while the
sibling non-UTF-8 branch already handles UnicodeDecodeError. Guard the UTF-8
decode and raise ZipImportError instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant