Skip to content

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).

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