You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bytearray.resize() must not clear the object on error (memory allocation failure) #157242
Python 3.15 reimplemented bytearray using an internal bytes object (to implement the bytearray.take_bytes() method). _PyBytes_Resize() is used internally to resize the bytearray object. Problem: if _PyBytes_Resize() fails, the bytearray object is cleared.
On Python 3.14, the bytearray is not cleared on resize failure.
The following example works on Python 3.14 but fails on Python 3.15.
3rd bug: bytearray.take_bytes() also clears the bytearray if _PyBytes_Resize() fails. At least, it's not a regression since the method is new in Python 3.15 :-)
Activity
pythongh-157242: Leave bytearray unchanged if resize() fails
vstinner commentedon Sep 10, 2026
The
PyBytesWriter_Resize()function has a similar issue: on failure,writer->objis set to NULL and the writer is left in an inconsistent state.vstinner commentedon Sep 10, 2026
3rd bug:
bytearray.take_bytes()also clears thebytearrayif_PyBytes_Resize()fails. At least, it's not a regression since the method is new in Python 3.15 :-)gh-157242: Fix PyBytesWriter_Resize() on MemoryError (#157243)
pythongh-157242: Do not close io.BytesIO on MemoryError
pythongh-157242: Do not close io.BytesIO on MemoryError
gh-157242: Leave bytearray unchanged if resize() fails (#157340)
gh-157242: Fix set_nomemory() on Py_TRACE_REFS build (#157351)
gh-157242: Add more PyBytesWriter tests (#157352)
pythongh-157242: Fix PyBytesWriter_Resize() on MemoryError (python#15…
pythongh-157242: Leave bytearray unchanged if resize() fails (python#…
pythongh-157242: Fix set_nomemory() on Py_TRACE_REFS build (python#15…
pythongh-157242: Add more PyBytesWriter tests (python#157352)
19 remaining items
gh-157242: Use support.inject_memory_error_cm() in tests (#157811)
pythongh-157242: Fix PyBytesWriter_Resize() on MemoryError (python#15…
[3.15] gh-157242: Fix PyBytesWriter_Resize() on MemoryError (#157243) (…
pythongh-157242: Leave bytearray unchanged if resize() fails (python#…
[3.15] gh-157242: Do not close io.BytesIO on MemoryError (GH-157344) (#…
[3.15] gh-157242: Leave bytearray unchanged if resize() fails (#157340)…
[3.15] gh-157242: Fix set_nomemory() on Py_TRACE_REFS build (#157351) (…
pythongh-157242: Fix set_nomemory() on Py_TRACE_REFS build (python#15…
[3.14] gh-157242: Do not close io.BytesIO on MemoryError (#159529)
[3.14] gh-157242: Fix set_nomemory() on Py_TRACE_REFS build (#157351) (…
gh-157242: Use support.inject_memory_error_cm() in test_dict (#159543)
[3.15] gh-157242: Add more PyBytesWriter tests (#159546)
[3.15] gh-157242: Add support.inject_memory_error() function (#159553)
[3.15] pythongh-157242: Add support.inject_memory_error() function (p…