Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-131998: FixNULL
dereference when using an unbound method descriptor in a specialized code path#132000
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
gh-131998: FixNULL
dereference when using an unbound method descriptor in a specialized code path#132000
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
(not a full review)
Lib/test/test_types.py Outdated
# GH-131998: The specialized instruction would get tricked into dereferencing | ||
# a bound "self" that didn't exist if subsequently called unbound. | ||
code = """if True: | ||
import glob |
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.
Do we need this import?
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.
Yeah, the optimizer is finicky and I can't get it to reliably reproduce without the import. I'll add a comment for clarity.
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.
I reproduce the crash in a reliable way without theimport glob
.
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.
Does it reliably reproduce in the test case? I think it only happens if you've already got some compiled bytecode to trigger the optimizer, which isn't the case in CI.
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.
You can replaceimport glob
with just this code copied fromLib/types.py
(a dependency ofglob
):
# CellType comes from types.pydef_cell_factory():a=1deff():nonlocalareturnf.__closure__[0]CellType=type(_cell_factory())
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.
I'm ok-ish with keepingimport glob
, but add a comment explaining the purpose of this unused import.
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.
Does it reliably reproduce in the test case? I think it only happens if you've already got some compiled bytecode to trigger the optimizer, which isn't the case in CI.
Sorry, I mean that I can reproduce the crash withoutimport glob
when I run a script:./python reproducer.py
. I confirm that for this test case,import glob
(or the code example that I proposed) is needed to trigger the bug.
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.
I added a comment.
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.
This import shouldn't be needed with the changes below.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: sobolevn <mail@sobolevn.me>
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
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.
We need to guardtotal_args
before readingself
.
This applies toCALL_METHOD_DESCRIPTOR_FAST
as well.
Uh oh!
There was an error while loading.Please reload this page.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @markshannon: please review the changes made to this pull request. |
This PR had a merge conflict. Next 3.13/3.14 releases are tomorrow. |
Fixed the conflicts. Friendly ping@markshannon -- this is a blocker for 3.13.3. |
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.
I think we can remove theimport glob
by filling the stack with lists before the call.
Uh oh!
There was an error while loading.Please reload this page.
Lib/test/test_types.py Outdated
# GH-131998: The specialized instruction would get tricked into dereferencing | ||
# a bound "self" that didn't exist if subsequently called unbound. | ||
code = """if True: | ||
import glob |
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.
This import shouldn't be needed with the changes below.
Uh oh!
There was an error while loading.Please reload this page.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
Co-authored-by: Mark Shannon <mark@hotpy.org>
FTR, here's the reproducer on main without importing >>>defcall(part):... []+ ([]+ [])...part.pop()...>>>for_inrange(3):...call(['a'])...>>>call(list)Segmentationfault (coredumped) |
I'm not going to trigger the noisy bot again, but this should be good to go. |
ac3c439
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@ZeroIntensity for the PR, and@Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry,@ZeroIntensity and@Yhg1s, I could not cleanly backport this to
|
I'll deal with the backport. |
…method descriptor in a specialized code path (pythonGH-132000)(cherry picked from commitac3c439)Co-authored-by: Peter Bierma <zintensitydev@gmail.com>Co-authored-by: sobolevn <mail@sobolevn.me>Co-authored-by: Victor Stinner <vstinner@python.org>Co-authored-by: Mark Shannon <mark@hotpy.org>
GH-132262 is a backport of this pull request to the3.13 branch. |
…descriptor in a specialized code path (python#132000)Co-authored-by: sobolevn <mail@sobolevn.me>Co-authored-by: Victor Stinner <vstinner@python.org>Co-authored-by: Mark Shannon <mark@hotpy.org>
Uh oh!
There was an error while loading.Please reload this page.