Skip to content

gh-135177: Raise OverflowError in _Py_call_instrumentation_jump to handle potential integer overflow #135202

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 7 commits into
base: main
Choose a base branch
from

Conversation

rialbat
Copy link
Contributor

@rialbat rialbat commented Jun 6, 2025

This pull request adds a runtime check to handle potential integer overflow in the _Py_call_instrumentation_jump function.

@ZeroIntensity ZeroIntensity requested a review from skirpichev June 6, 2025 10:52
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
skirpichev
skirpichev previously approved these changes Jun 6, 2025
Clarified that we are referring to the int type in C.

Co-authored-by: Victor Stinner <vstinner@python.org>
…ential overflow

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member

vstinner commented Jun 6, 2025

@skirpichev @ZeroIntensity: So what do you think? Is it worth it to fix this issue? Are you ok with Py_ssize_t and an assertion?

@skirpichev skirpichev dismissed their stale review June 6, 2025 11:48

to <= INT_MAX / (int)sizeof(_Py_CODEUNIT) seems broken in tests

… to Py_ssize_t for type consistency in assert

Co-authored-by: Victor Stinner <vstinner@python.org>
@ZeroIntensity
Copy link
Member

Yeah, an assertion makes more sense to me. I'm pretty sure it would take several years for Python to compile code that actually triggers the assertion.

@skirpichev
Copy link
Contributor

Is it worth it to fix this issue?

It's definitely worth, as it seems that assumptions for the current code - broken in CI tests.

With replacement to Py_ssize_t (for to) - I think that assertion makes more sense than an exception.

@markshannon
Copy link
Member

There is no risk of overflow. The bytecode compiler ensures that the size of the code is within bounds for a 32 bit int.
We should probably document what the actual limit it is.

@vstinner
Copy link
Member

vstinner commented Jun 6, 2025

There is no risk of overflow.

Do you suggest to close the PR?

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.

5 participants