Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91153: Fix bytearray holding a reference to its internal buffer when calling into potentially mutating __index__ methods#132379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
picnixz merged 9 commits intopython:mainfrombast0006:bast0006/gh-91153
Jul 12, 2025

Conversation

bast0006
Copy link
Contributor

@bast0006bast0006 commentedApr 10, 2025
edited by bedevere-appbot
Loading

bytearray's__setitem__ implementation currently grabs a reference to its internal buffer before calling_getbyvalue to determine the index that needs assignment._getbyvalue can call into arbitrary python code via__index__ dunders, which could alter the internal buffer and leave said reference dangling.

A prior fix for this issue ensures that bounds checking occurs after_getbyvalue is called. However, python code is capable of resizing the bytearray, resulting in limited but still broken behavior.

This patch ensures that the reference to the internal buffer is fetched only after_getbyvalue is called to prevent it from being held while any python code is run.

@python-cla-bot
Copy link

python-cla-botbot commentedApr 10, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

bast0006 reacted with thumbs up emoji

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@bast0006
Copy link
ContributorAuthor

bast0006 commentedApr 10, 2025
edited
Loading

I've signed the CLA. Let me know if a NEWS entry is required. I'm not sure it is, especially since there was already a previous change that this is a fix to.

@picnixzpicnixz self-requested a reviewMay 17, 2025 11:00
Copy link
Member

@picnixzpicnixz left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add a NEWS entry please? It's still worth to mention that we fixed more crashes.

@bast0006
Copy link
ContributorAuthor

Done

@bast0006bast0006 requested a review frompicnixzMay 17, 2025 23:25
@ZeroIntensityZeroIntensity added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsMay 18, 2025
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@@ -1889,6 +1889,39 @@ def __index__(self):
withself.assertRaises(IndexError):
self._testlimitedcapi.sequence_setitem(b,0,Boom())

deftest_mutating_index_inbounds(self):
# See gh-91153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you add a brief description of the issue?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

2 NITS and I'll merge.

@picnixzpicnixzenabled auto-merge (squash)July 12, 2025 13:15
@picnixzpicnixz merged commit5e1e21d intopython:mainJul 12, 2025
41 checks passed
@miss-islington-app
Copy link

Thanks@bast0006 for the PR, and@picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJul 12, 2025
…when `ind.__index__` has side-effects (pythonGH-132379)(cherry picked from commit5e1e21d)Co-authored-by: Bast <52266665+bast0006@users.noreply.github.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@miss-islington-app
Copy link

Sorry,@bast0006 and@picnixz, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 5e1e21dee35b8e9066692d08033bbbdb562e2c28 3.13

@bedevere-app
Copy link

GH-136581 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelJul 12, 2025
picnixz added a commit to picnixz/cpython that referenced this pull requestJul 12, 2025
… ...)` when `ind.__index__` has side-effects (pythonGH-132379)(cherry picked from commit5e1e21d)Co-authored-by: Bast <52266665+bast0006@users.noreply.github.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

GH-136582 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJul 12, 2025
picnixz added a commit that referenced this pull requestJul 12, 2025
… when `ind.__index__` has side-effects (GH-132379) (#136582)(cherry picked from commit5e1e21d)Co-authored-by: Bast <52266665+bast0006@users.noreply.github.com>
picnixz added a commit that referenced this pull requestJul 12, 2025
… when `ind.__index__` has side-effects (GH-132379) (#136581)gh-91153: prevent a crash in `bytearray.__setitem__(ind, ...)` when `ind.__index__` has side-effects (GH-132379)(cherry picked from commit5e1e21d)Co-authored-by: Bast <52266665+bast0006@users.noreply.github.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull requestJul 12, 2025
…when `ind.__index__` has side-effects (python#132379)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz added a commit to picnixz/cpython that referenced this pull requestJul 13, 2025
…when `ind.__index__` has side-effects (python#132379)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz approved these changes

@ZeroIntensityZeroIntensityZeroIntensity approved these changes

Assignees

@picnixzpicnixz

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@bast0006@picnixz@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp