Skip to content

gh-130070: Fix exec(<string>, closure=<non-None>) unexpected path #130071

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

Merged
merged 8 commits into from
Apr 17, 2025

Conversation

bswck
Copy link
Contributor

@bswck bswck commented Feb 13, 2025

Closes gh-130070

@bswck bswck changed the title Fix exec(<string>, closure=<non-None>) segfault gh-130070: Fix exec(<string>, closure=<non-None>) segfault Feb 13, 2025
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.

Before:

» ./python.exe                                                                         
Python 3.14.0a5+ (heads/main:625470a7d2c, Feb 13 2025, 10:38:58) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exec("", closure=object())
Assertion failed: (!PyErr_Occurred()), function _PyAST_Validate, file ast.c, line 1047.
[1]    91990 abort      ./python.exe

After: all tests pass.

Do we need to backport this?

Copy link
Member

@Eclips4 Eclips4 left a comment

Choose a reason for hiding this comment

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

LGTM.

Co-authored-by: sobolevn <mail@sobolevn.me>
@bswck
Copy link
Contributor Author

bswck commented Feb 13, 2025

Do we need to backport this?

I'd say no, because it never worked.

NVM, this issue seems to be specific to my debug build: #130070 (comment).

@bswck bswck changed the title gh-130070: Fix exec(<string>, closure=<non-None>) segfault gh-130070: Fix exec(<string>, closure=<non-None>) unexpected path Feb 13, 2025
@bswck
Copy link
Contributor Author

bswck commented Feb 13, 2025

Sorry, I'm still new to C 😅 This isn't a segfault, it's a fix for failed assertion. The program was stopped by the SIGABRT signal, not SIGSEGV. My bad!

@bswck
Copy link
Contributor Author

bswck commented Feb 13, 2025

I'd also change the branch name, but that would close the PR as a side effect

@tomasr8
Copy link
Member

tomasr8 commented Feb 13, 2025

I'd also change the branch name, but that would close the PR as a side effect

I don't think that's needed, the branch name is usually not relevant :)

@bswck
Copy link
Contributor Author

bswck commented Feb 18, 2025

I think we can backport this.

@tomasr8
Copy link
Member

tomasr8 commented Feb 18, 2025

I think we can backport this.

Does it also crash on 3.12 and 3.13? If yes, let's backport it

@bswck
Copy link
Contributor Author

bswck commented Feb 18, 2025

Reproduced on 3.12 and 3.13.

❯ python -VV && python -c 'exec("", closure=object())'
Python 3.12.9+ (heads/3.12:0931693f95b, Feb 18 2025, 16:24:22) [GCC 11.4.0]
python: Python/ast.c:1044: _PyAST_Validate: Assertion `!PyErr_Occurred()' failed.
Aborted
❯ python -VV && python -c 'exec("", closure=object())'
Python 3.13.2+ (heads/3.13:57e8b0cbee1, Feb 18 2025, 16:30:24) [GCC 11.4.0]
python: Python/ast.c:1049: _PyAST_Validate: Assertion `!PyErr_Occurred()' failed.
Aborted

Let's backport! 🚀

@tomasr8 tomasr8 added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Feb 18, 2025
@bswck
Copy link
Contributor Author

bswck commented Mar 10, 2025

@sobolevn @Eclips4 Are we ready for merge?

@bswck
Copy link
Contributor Author

bswck commented Apr 16, 2025

@sobolevn @Eclips4 bump

@Eclips4 Eclips4 removed the needs backport to 3.12 only security fixes label Apr 17, 2025
@Eclips4 Eclips4 merged commit 954b2cf into python:main Apr 17, 2025
48 checks passed
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

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

cherry_picker 954b2cf031fb84ff3386251d5c45281f47229003 3.13

@Eclips4
Copy link
Member

Eclips4 commented Apr 17, 2025

@bswck Would you mind creating a manual backport for 3.13? :)
(3.12 is in security-fixes-only mode, so the backport is only needed for 3.13)

@bswck
Copy link
Contributor Author

bswck commented Apr 17, 2025

Yes, sure!

bswck added a commit to bswck/cpython that referenced this pull request Apr 17, 2025
…path (python#130071)

Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf)
bswck added a commit to bswck/cpython that referenced this pull request Apr 17, 2025
…path (python#130071)

Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf)
bswck added a commit to bswck/cpython that referenced this pull request Apr 17, 2025
…path (python#130071)

Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf)
@bedevere-app
Copy link

bedevere-app bot commented Apr 17, 2025

GH-132627 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Apr 17, 2025
Eclips4 pushed a commit that referenced this pull request Apr 17, 2025
… path (GH-130071) (#132627)

gh-130070: Fix `exec(<string>, closure=<non-None>)` unexpected path (#130071)

Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf)
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.

exec(<string>, closure=<non-None>) failed assertion
4 participants