Skip to content

[3.15] gh-153570: Fix use-after-free in bytearray.take_bytes() with a reentrant __index__ (GH-153572) - #154648

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

[3.15] gh-153570: Fix use-after-free in bytearray.take_bytes() with a reentrant __index__ (GH-153572)#154648
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-ee21d99-3.15

Conversation

@miss-islington

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

Copy link
Copy Markdown
Contributor

bytearray.take_bytes() cached the size before the argument's index call and
used it for the bounds check and the buffer reads, so an index that resizes
the bytearray left it reading freed memory. Re-read the size after index,
matching bytearray.setitem (GH-91153).
(cherry picked from commit ee21d99)

Co-authored-by: tonghuaroot (童话) tonghuaroot@gmail.com

…reentrant __index__ (pythonGH-153572)

bytearray.take_bytes() cached the size before the argument's __index__ call and
used it for the bounds check and the buffer reads, so an __index__ that resizes
the bytearray left it reading freed memory. Re-read the size after __index__,
matching bytearray.__setitem__ (pythonGH-91153).
(cherry picked from commit ee21d99)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
@vstinner
vstinner merged commit 848f0ba into python:3.15 Jul 24, 2026
59 checks passed
@miss-islington
miss-islington deleted the backport-ee21d99-3.15 branch July 24, 2026 22:06
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.

4 participants