Skip to content

Missing recursion checks building long lazy import alias can segfault #159288

Open

Description

@brittanyrey

Crash report

Bug: When lazily importing a long dotted named module using an alias, nested placeholders are used for each name to build the full chain recursively. If the dotted module name is long enough (import a.b.c.d.etc as foo), it's possible to overflow the C stack and segfault.

Severity: It's likely that these use cases would rarely be hit, but they do segfault when using lazy imports and they do not with eager imports, so I think it's still worth a small fix.

examples

Both tests leverage threading to reduce the available stack size.

Resolving from repr:

import threading
exec("lazy import " + ".".join(["m"] * 10_000) + " as x")
threading.stack_size(256 * 1024)
t = threading.Thread(target=repr, args=(globals()["x"],))
t.start(); t.join()
Segmentation fault (core dumped)

Resolving via a function call:

import threading
exec("lazy import " + ".".join(["m"] * 10_000) + " as x")
def f():
    x
threading.stack_size(256 * 1024)
t = threading.Thread(target=f)
t.start(); t.join()
Segmentation fault (core dumped)

CPython versions tested on:

3.15

Operating systems tested on:

Linux

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

No response

Linked PRs

Activity

  1. StanFromIreland commented on Oct 13, 2026

    @StanFromIreland
    Member

    Hmm, we don't use the Priority field here, maybe it should be disabled like the other ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-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