Skip to content

[3.15] gh-153419: Fix several issues around bytearray __init__ (GH-153498)#154622

Merged
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-d5c1b29-3.15
Jul 24, 2026
Merged

[3.15] gh-153419: Fix several issues around bytearray __init__ (GH-153498)#154622
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-d5c1b29-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Introduce a bytearray_new() function to ensure that
ob_bytes_object is always set on a bytearray.

Resizing a bytearray to 0 length now explicitly sets
the ob_bytes_object to the empty constant immortal.

Add a check in the 'bytearray init from string'
fast path to ensure there are no active exports.

This fixes asserts/crashes on the following:

  • bytearray(1).init()
  • bytearray().new(bytearray).append(1)
  • a = bytearray(); b = memoryview(a); a.init('x', 'ascii')
    (cherry picked from commit d5c1b29)

Co-authored-by: Steve Stagg stestagg@gmail.com
Co-authored-by: Cody Maloney cmaloney@users.noreply.github.com

…GH-153498)

Introduce a bytearray_new() function to ensure that
ob_bytes_object is always set on a bytearray.

Resizing a bytearray to 0 length now explicitly sets
the ob_bytes_object to the empty constant immortal.

Add a check in the 'bytearray init from string'
fast path to ensure there are no active exports.

This fixes asserts/crashes on the following:
 - bytearray(1).__init__()
 - bytearray().__new__(bytearray).append(1)
 - a = bytearray(); b = memoryview(a); a.__init__('x', 'ascii')
(cherry picked from commit d5c1b29658063d1ef9d66515d8e4cb9929126be7)

Co-authored-by: Steve Stagg <stestagg@gmail.com>
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
@vstinner
vstinner merged commit 370e670 into python:3.15 Jul 24, 2026
55 checks passed
@miss-islington
miss-islington deleted the backport-d5c1b29-3.15 branch July 24, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants