Skip to content

gh-159288: Avoid segfault by adding missing recursion checks when walking lazy import chains - #159289

Merged
Yhg1s merged 2 commits into
python:mainfrom
brittanyrey:b-lazy-import-deep-chain
Oct 14, 2026
Merged

Yhg1s merged 2 commits into
python:mainfrom
brittanyrey:b-lazy-import-deep-chain

Conversation

@brittanyrey

@brittanyrey brittanyrey commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

lazy import a.b.c as d nests one placeholder per name component. lazy_import_path() and lazy_import_replay_from() recursed over that chain without a recursion check, so a very long dotted name could overflow the stack.

Add guards to raise a RecursionError instead of failing into a segfault.

`lazy import a.b.c as d` nests one placeholder per name component.
lazy_import_path() and lazy_import_replay_from() recursed over that
chain without a recursion check, so a very long dotted name could
overflow the C stack. Raise RecursionError instead, as the rest of
lazy import resolution does.
@Yhg1s

Yhg1s commented Oct 13, 2026

Copy link
Copy Markdown
Member

FYI, the Android test failure should be fixed by either one of the PRs attached to #159320...

@Yhg1s Yhg1s added the needs backport to 3.15 bugs and security fixes label Oct 14, 2026
@Yhg1s
Yhg1s enabled auto-merge (squash) October 14, 2026 13:18
@Yhg1s
Yhg1s merged commit 2588362 into python:main Oct 14, 2026
58 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @brittanyrey for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 14, 2026

Copy link
Copy Markdown

GH-159416 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants