Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SystemError/Assertion failure when processing struct with '0p' field #124248

Closed
Labels
extension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump
@brianschubert

Description

@brianschubert

Crash report

What happened?

Usingstruct to process zero-width Pascal strings ("0p") can lead to an assertion failure orSystemError.

Specifically:

  • struct.pack("<0p", b"") leads to an assertion failure and seg fault on debug builds (tested with currentmain and 3.13 tip)
  • struct.unpack("<0p", b"") raises an unexpectedSystemError (tested with currentmain, 3.13 tip, non-debug builds of 3.8-3.12)

On currentmain (8f82d9aa219):

$ make clean&& ./configure --with-pydebug&& make -j$ ./python -VVPython 3.14.0a0 (heads/main:8f82d9aa219, Sep 19 2024, 11:08:04) [GCC 11.4.0]$ ./python -c'import struct; struct.unpack("<0p", b"")'Traceback (most recent call last):  File"<string>", line 1,in<module>    import struct; struct.unpack("<0p", b"")~~~~~~~~~~~~~^^^^^^^^^^^^SystemError: Negative size passed to PyBytes_FromStringAndSize$ ./python -c'import struct; struct.pack("<0p", b"")'python: ./Modules/_struct.c:1991: s_pack_internal: Assertion`_Py_STATIC_CAST(Py_ssize_t, _Py_STATIC_CAST(unsigned char, (n))) == (n)' failed.[1]    186971 IOT instruction (core dumped)  ./python -c'import struct; struct.pack("<0p", b"")'

The same behavior is reproducible on the current 3.13 tip (112b1704fa6), and likely previous versions.

PR forthcoming.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.14.0a0 (heads/main:8f82d9aa219, Sep 19 2024, 11:08:04) [GCC 11.4.0]

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp