Skip to content

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

Open
@markshannon

Description

@markshannon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions