Skip to content

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

Merged
cmaloney merged 4 commits into
python:mainfrom
cmaloney:triage-158928-bytearray-init
Nov 5, 2026
Merged

cmaloney merged 4 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 <noreply@anthropic.com>
Comment thread Lib/test/test_bytes.py Resolved
@cmaloney
cmaloney merged commit 25181ce into python:main Nov 5, 2026
56 checks passed
@cmaloney
cmaloney deleted the triage-158928-bytearray-init branch November 5, 2026 21:29
@cmaloney cmaloney added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 5, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @cmaloney for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @cmaloney for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

GH-161447 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 5, 2026
@bedevere-app

bedevere-app Bot commented Nov 5, 2026

Copy link
Copy Markdown

GH-161448 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 5, 2026
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.

1 participant