Skip to content

gh-135177: Add assert to catch potential overflow #135179

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

Closed
wants to merge 1 commit into from

Conversation

rialbat
Copy link
Contributor

@rialbat rialbat commented Jun 5, 2025

This pull request adds an assertion to the _Py_call_instrumentation_jump function to catch potential integer overflow in the expression to * (int)sizeof(_Py_CODEUNIT).

@@ -1236,6 +1236,7 @@ _Py_call_instrumentation_jump(
event == PY_MONITORING_EVENT_BRANCH_RIGHT ||
event == PY_MONITORING_EVENT_BRANCH_LEFT);
int to = (int)(dest - _PyFrame_GetBytecode(frame));
assert(to <= INT_MAX / (int)sizeof(_Py_CODEUNIT));
Copy link
Member

Choose a reason for hiding this comment

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

If there is a real risk that this case occurs, I would prefer to raise an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean something like this?

if (to <= INT_MAX / (int)sizeof(_Py_CODEUNIT)) {
    PyErr_SetString(PyExc_OverflowError, "instruction offset is too large for int");
    return 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, added
#135202

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will close this one request

@rialbat rialbat closed this Jun 6, 2025
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.

2 participants