Skip to content

struct: non-ASCII bytes format raises UnicodeEncodeError instead of struct.error on 3.13/3.14 #158172

Description

@corona10

Bug report

#153835 (backport of gh-85943) introduces a regression on 3.13 and 3.14. A bytes format with a non-ASCII byte now raises UnicodeEncodeError instead of struct.error:

>>> import struct
>>> struct.unpack(b'\xc5', b'')
UnicodeEncodeError: 'ascii' codec can't encode character '\udcc5' in position 0: ordinal not in range(128)

3.14.0 raises struct.error: bad char in struct format. main is not affected since gh-145850 already rejects non-ASCII formats with ValueError.

This aborts fuzz_struct_unpack, so CIFuzz fails on any 3.14 PR that touches C files, e.g. gh-158162: https://github.com/python/cpython/actions/runs/36136424084/job/108075564322

UnicodeEncodeError: 'ascii' codec can't encode character '\udcc5' in position 0: ordinal not in range(128)
==75== ERROR: libFuzzer: deadly signal
    #6 0x55d07f8c7884 in _run_fuzz /src/cpython3/Modules/_xxtestfuzz/fuzzer.c:575:9
    #7 0x55d07f8c7884 in LLVMFuzzerTestOneInput /src/cpython3/Modules/_xxtestfuzz/fuzzer.c:640:11
Base64: xQA=

Linked PRs

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

    3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions