Skip to content
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

bpo-41631: Check that importing _ast returns the right module #21973

Closed
wants to merge 4 commits into from

Conversation

encukou
Copy link
Member

@encukou encukou commented Aug 26, 2020

Hopefully #21961 will be OK, but if not: here is a relatively minimal fix for bpo-41631, which basically makes compiling to/from AST fail gracefully (with a proper exception rather than a NULL without exception) if the _ast module has been tampered with.
For example, it looks like Mercurial's lazy-loading scheme replaces _astwith a proxy object; this will make AST unusable.

The second commit deals with a hack in pegen's tests – please review the commits separately, and see comments.

https://bugs.python.org/issue41631

@encukou
Copy link
Member Author

encukou commented Sep 8, 2020

@pablogsal, does this make sense for peg_generator? (Keeping in mind this would be a last-minute fix for 3.9, with a better solution hopefully coming in 3.10.)

@pablogsal
Copy link
Member

@pablogsal, does this make sense for peg_generator? (Keeping in mind this would be a last-minute fix for 3.9, with a better solution hopefully coming in 3.10.)

Yup, it does sense to me as a temporary solution 👍

encukou and others added 2 commits September 9, 2020 10:38
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
The previous behavior didn't always segfault -- in fact, it usually
raised a SystemError as well. A segfault (or any other behavior,
depending on the module object imported as _ast) was still *possible*,
but for that level of detail people should see the bpo issue.
@vstinner
Copy link
Member

Thanks for the workaround. PR 21961 fix has been merged instead.

@vstinner vstinner closed this Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants