Skip to content

gh-129573: Fix possible abort from non-string suggestions in calculate_suggestions/_Py_CalculateSuggestions #130997

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

devdanzin
Copy link
Contributor

@devdanzin devdanzin commented Mar 9, 2025

This PR adds a simple check that suggestion candidates are strings in calculate_suggestions(3.12)/_Py_CalculateSuggestions(main), avoiding an abort in debug builds from code like below:

import runpy
runpy._run_module_code("blech", {0: "", "bluch": ""}, "")

The abort only happens in 3.12, because the code in main checks for non-string candidates in _suggestions__generate_suggestions_impl. However, since the affected code is still present in main, this PR is against that branch.

In main, the code above exits the new REPL, which will be reported as a new issue with associated PR.

Found using fusil by @vstinner.

@vstinner
Copy link
Member

test_traceback is failing on the CI.

@tomasr8 tomasr8 removed the needs backport to 3.12 only security fixes label Apr 10, 2025
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@vstinner
Copy link
Member

@devdanzin: Tests are failing on your PR, and you didn't sign the CLA. What's the status of this PR?

@devdanzin
Copy link
Contributor Author

I'm sorry, I've left this one fall behind. Would you like to take it over?

I have signed the CLA and even contributed some trivial code, I'll wait to see if it's a CLA bot issue or my CLA status changed to unverified somehow.

def test_suggestions_do_not_trigger_with_non_string_candidates(self):
def run_module_code():
import runpy
runpy._run_module_code("blech", {0: "", "bluch": ""}, "")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
runpy._run_module_code("blech", {0: "", "bluch": ""}, "")
# non-string global variable
runpy._run_module_code("blech", {0: "", "bluch": ""}, "")

@@ -4740,6 +4740,13 @@ def test_suggestions_extension(self):
None
)

self.assertRaises(
TypeError,
_suggestions._generate_suggestions,
Copy link
Member

Choose a reason for hiding this comment

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

_suggestions._generate_suggestions() checks if all elements are strings before calling _Py_CalculateSuggestions(). So this test doesn't check changed code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy