Skip to content

gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg #126239

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

federicovalenso
Copy link
Contributor

@federicovalenso federicovalenso commented Oct 31, 2024

@bedevere-app
Copy link

bedevere-app bot commented Oct 31, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

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

@federicovalenso federicovalenso marked this pull request as ready for review October 31, 2024 13:15
Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

Can we cover this with a test?

@ZeroIntensity
Copy link
Member

I'm not exactly sure how to trigger it, it was found via a static analyzer.

@@ -0,0 +1 @@
Fix a possible crash internally when compiling.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to drop this NEWS entry.

Copy link
Member

Choose a reason for hiding this comment

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

I concur (that's what I did for #126241 because it's a bit hard to phrase it properly and meaningfully).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

drop this NEWS entry

Done )

Copy link
Member

Choose a reason for hiding this comment

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

Why? This seems user-facing to me, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sobolevn, @picnixz , what's the bottom line? Is news entry required or not?

Copy link
Member

@picnixz picnixz Nov 1, 2024

Choose a reason for hiding this comment

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

The bottom line in general is whether this kind of bug can be triggered easily using public interface. Unless you have a reproducer saying that with X and Y you can do Z, or unless the interface is publicly documented and known to the outside world, a NEWS entry would be fine. But here, we have neither a test nor is _PyCompile_LookupArg something that is exposed to the world.

As an end-user, reading "Fix a possible crash internally when compiling." gives me no information at all except that there was a bug I wasn't aware of (and that it was not always triggerable). I don't know how to make the crash happen, nor do I know what was crashing.

@picnixz picnixz added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes skip news labels Oct 31, 2024
@@ -901,7 +901,7 @@ _PyCompile_LookupArg(compiler *c, PyCodeObject *co, PyObject *name)
c->u->u_metadata.u_name,
co->co_name,
freevars);
Copy link
Member

Choose a reason for hiding this comment

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

Does PyErr_Format work for null?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, %R formats it as "<NULL>"

@ruidazeng
Copy link

I'm not exactly sure how to trigger it, it was found via a static analyzer.

Can you be more specific? I cannot reproduce this internal crash.

@ZeroIntensity
Copy link
Member

Can you be more specific? I cannot reproduce this internal crash.

See GH-126238. Looking at the source, this can only fail in some rare cases when a memory allocation fails, but it's pretty clearly wrong if that was the case so we might as well fix it.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

I'm happy with it.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you, congrats on your first merged PR :)

@sobolevn sobolevn merged commit 8525c93 into python:main Nov 5, 2024
45 checks passed
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

Sorry, @federicovalenso and @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8525c9375f25e6ec0c0b5dfcab464703f6e78082 3.13

@miss-islington-app
Copy link

Sorry, @federicovalenso and @sobolevn, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8525c9375f25e6ec0c0b5dfcab464703f6e78082 3.12

@ZeroIntensity
Copy link
Member

See the devguide if you want to know how to do that.

@federicovalenso
Copy link
Contributor Author

@sobolevn , @ZeroIntensity , I'll try to do that)

federicovalenso added a commit to federicovalenso/cpython that referenced this pull request Nov 6, 2024
…vars in _PyCompile_LookupArg (pythonGH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: Valery Fedorenko <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
@federicovalenso
Copy link
Contributor Author

federicovalenso commented Nov 6, 2024

@sobolevn , could you please look at #126474, #126475 )

federicovalenso added a commit to federicovalenso/cpython that referenced this pull request Nov 6, 2024
…vars in _PyCompile_LookupArg (pythonGH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: Valery Fedorenko <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
sobolevn pushed a commit that referenced this pull request Nov 6, 2024
…e_LookupArg (gh-126238) (#126474)

[3.12] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
sobolevn pushed a commit that referenced this pull request Nov 6, 2024
…e_LookupArg (gh-126238) (#126475)

[3.13] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
@ambv ambv removed needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Nov 12, 2024
picnixz pushed a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
… _PyCompile_LookupArg (python#126239)

* Replace Py_DECREF by Py_XDECREF

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
… _PyCompile_LookupArg (python#126239)

* Replace Py_DECREF by Py_XDECREF

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[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.

7 participants