Skip to content

[3.14] gh-158928: Fix overflow in bytearray.__init__ from an iterator (GH-158947) - #161447

Merged
cmaloney merged 1 commit into
python:3.14from
miss-islington:backport-25181ce-3.14
Nov 5, 2026
Merged

cmaloney merged 1 commit into
python:3.14from
miss-islington:backport-25181ce-3.14

Conversation

@miss-islington

@miss-islington miss-islington commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Passing an iterator to bytearray.__init__ didn't take into account
that iterating that iterator could modify the bytearray position and
ob_start. When that happened the iterator would write beyond the end
of the allocation.

Update the "enough space" check to account for ob_start. The
assignment always included it. Add an assert after append that the
offsets line up as expected.
(cherry picked from commit 25181ce)

Co-authored-by: Cody Maloney cmaloney@users.noreply.github.com
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

…ythonGH-158947)

Passing an iterator to `bytearray.__init__` didn't take into account
that iterating that iterator could modify the bytearray position and
`ob_start`. When that happened the iterator would write beyond the end
of the allocation.

Update the "enough space" check to account for `ob_start`. The
assignment always included it. Add an assert after append that the
offsets line up as expected.
(cherry picked from commit 25181ce)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cmaloney cmaloney self-assigned this Nov 5, 2026
@cmaloney
cmaloney merged commit 7ed3bb8 into python:3.14 Nov 5, 2026
51 checks passed
@miss-islington
miss-islington deleted the backport-25181ce-3.14 branch November 5, 2026 22:14
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.

2 participants