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

Merge checks for Python recursion limit and stack buffer overflow. #620

Open
markshannon opened this issue Sep 1, 2023 · 1 comment
Open

Comments

@markshannon
Copy link
Member

On making a call to a Python function we need to check if there is room for the frame in the frame buffer (_PyThreadState_HasStackSpace) and check the Python recursion limit(_Py_EnterRecursivePy).

The first checks tstate->datastack_top != NULL && size < tstate->datastack_limit - tstate->datastack_top and the second that tstate->py_recursion_remaining > 1.

Given that frames have a minimum size, we can set create a tstate->slots_remaining value, such that slots_remaining <= tstate->datastack_limit - tstate->datastack_top and slots_remaining <= py_recursion_remaining * FRAME_SPECIALS_SIZE. We set slots_remaining to -1 if the datastack is NULL.

Then the check size < tstate->slots_remaining would suffice to check that the data stack is not NULL, for data stack overflow and for the recursion limit all in a single check.

This is unlikely to make much difference overall, but it streamlines calls a bit.

@markshannon
Copy link
Member Author

(Closed by mistake)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant