Skip to content

Is it OK to implement stack protection? #102

@markshannon

Description

@markshannon

C stack overflow has lately been a problem for building and testing CPython, and it is a concern that it may impact users as well.
The root cause is that compilers, especially Clang use a lot more C stack for debug builds, meaning that at the full default recursion limit of 1000, C stack overflows are likely.

I would like to fix CPython to raise an exception (for major platforms at least) instead of faulting. We already do this partially for Windows.

PEP 651 proposed doing this, but was rejected. I don't want to appear to be implementing PEP 651 by stealth, so I wanted the SC's approval first.

PEP 651 included the following:

StackOverflow exception

A StackOverflow exception will be raised whenever the interpreter or builtin module code determines that the C stack is at or nearing a limit of safety. StackOverflow is a sub-class of RecursionError, so any code that handles RecursionError will handle StackOverflow.

I plan to implement the above check, but without adding a new Exception type, raising a RecursionError as happens when the recursion limit is reached.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions