Skip to content

zipapp.get_interpreter() raises UnicodeDecodeError on invalid shebang bytes #158546

Description

@Tony123-tech

zipapp.get_interpreter() raises UnicodeDecodeError when the shebang
line contains bytes that aren't valid in shebang_encoding, instead of
returning None.

Reproducer:

import zipapp, tempfile, os
d = tempfile.mkdtemp()
p = os.path.join(d, "a.pyz")
with open(p, "wb") as f:
    f.write(b"#!\xff\xfe\xff\xfe\nx")
print(repr(zipapp.get_interpreter(p)))

Actual:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Expected:
None (treat undecodable shebang as "no interpreter")

The function already returns None for "no shebang", so returning
None for an undecodable shebang is consistent. The CLI renders
None as <none>.

Tested on: main.

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