Skip to content

Calling map on maps many times causes segfault #103503

@AFK-debug-9

Description

@AFK-debug-9

Crash report

When the following code is ran, It causes a Segmentation Fault:

a = []
for x in range(100_000):
    a = map(int, a)
list(a)

Now the list call calls Python/bltinmodule.c:map_next.
If we run the code with gdb, we get the following:

Program received signal SIGSEGV, Segmentation fault.

But we also get:

0x00005555557bbd6e in map_next (lz=0x7ffff7099ba0) at Python/bltinmodule.c:1342

To inspect the call stack, we can type where into gdb and we get loads of function calls, all seeming to be coming from line 1363, which is:

PyObject *val = Py_TYPE(it)->tp_iternext(it);

And the value of Py_TYPE(it) is a map and it calls map_next which causes the recursion

Error message

Segmentation Fault

Core file

Core file: Google Drive Link

Possible fix

We could add a recursion limit like we have with regular python functions.

Your environment

  • CPython versions tested on: 3.9, 3.10, 3.12.0a5+
  • Operating system and architecture: Windows & Linux, x86-64

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-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