Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
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
Conversation
…ay allocation during item assignment
python-cla-botbot commentedApr 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 the |
bast0006 commentedApr 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
picnixz left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Done |
Misc/NEWS.d/next/Core_and_Builtins/2025-05-17-18-22-12.gh-issue-91153.ioA_83.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core_and_Builtins/2025-05-17-20-56-05.gh-issue-91153.afgtG2.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/test/test_bytes.py Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Done
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this 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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
5e1e21d
intopython:mainUh oh!
There was an error while loading.Please reload this page.
…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>
Sorry,@bast0006 and@picnixz, I could not cleanly backport this to
|
GH-136581 is a backport of this pull request to the3.14 branch. |
… ...)` 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>
GH-136582 is a backport of this pull request to the3.13 branch. |
… 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>
…when `ind.__index__` has side-effects (python#132379)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…when `ind.__index__` has side-effects (python#132379)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
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.__index__
with side-effects #91153