Skip to content

gh-158928: Fix overflow in bytearray.__init__ from an iterator - #158947

Open
cmaloney wants to merge 2 commits into
python:mainfrom
cmaloney:triage-158928-bytearray-init
Open

cmaloney wants to merge 2 commits into
python:mainfrom
cmaloney:triage-158928-bytearray-init

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 7, 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.

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.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant