python / cpython

The Python programming language
https://www.python.org
Other
63.49k stars 30.41k forks source link

Failed assertion in typeobject.c::wrap_buffer for `b"".__buffer__(-2**31 - 1)` #126594

Open devdanzin opened 1 week ago

devdanzin commented 1 week ago

Crash report

What happened?

Calling bytes_object.__buffer__(large_negative_number) in a debug build aborts with this message:

>>> b"".__buffer__(-2**31 - 1)
python: Objects/typeobject.c:9321: wrap_buffer: Assertion `_Py_STATIC_CAST(Py_ssize_t, _Py_STATIC_CAST(int, (flags))) == (flags)' failed.
Aborted

Found using fusil by @vstinner.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux, Windows

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

Python 3.14.0a1+ (heads/main:4ea214ea982, Nov 6 2024, 00:52:15) [MSC v.1941 64 bit (AMD64)]

Linked PRs

vstinner commented 3 days ago

I wrote PR gh-126754 to fix the issue.