Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-crashA hard crash of the interpreter, possibly with a core dump
Description
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
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-crashA hard crash of the interpreter, possibly with a core dump
Activity
StanFromIreland commentedon Oct 13, 2026
Hmm, we don't use the Priority field here, maybe it should be disabled like the other ones.
gh-159288: Avoid segfault by adding missing recursion checks when wal…
[3.15] gh-159288: Avoid segfault by adding missing recursion checks w…
Bound lazy-import chain walks with a recursion check