Skip to content

Segmentation fault in Python 3.13 when chaining deep filter() iterators #137894

@hutuhutong

Description

@hutuhutong

Crash report

What happened?

When creating a deeply nested chain of filter() iterators, Python 3.12 can handle it (although very slow), but Python 3.13 results in a segmentation fault instead of raising an exception.

This appears to be a regression in Python 3.13’s iterator implementation, as user code should never cause a segfault. Ideally, this should raise a RecursionError or another Python exception, not crash the interpreter.

if __name__ == '__main__':
    import sys
    import gc
    
    def main():
        i = filter(bool, range(1000000))
        for _ in range(100000):
            i = filter(bool, i)
        print(list(i))

    #sys.setrecursionlimit(1000000)
    main()

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.2 crashes with:Segmentation fault (core dumped) Python 3.12.9 executes successfully (though very slow).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions