fix: guard circular import/load_file against C-stack SIGSEGV (#496)#513
Merged
Conversation
A mutual or self-referential `import` (a→b→a) or `load_file` (a↔b) recursed through vm_execute until the C stack overflowed — SIGSEGV, rc=139, uncatchable. The module cache is only populated after a load completes, so a re-entrant load of a still-loading path missed the cache and recursed. Add a per-EigsState in-flight load stack (eigs_loading_active/enter/leave) recording paths whose load is currently on the C stack. The import opcode checks it on cache-miss; load_file keys on the canonical realpath. On a cycle the loader raises a catchable EK_IO error instead of recursing. Shared by both loaders so a cross-loader cycle (import → load_file → import) is caught too. Repeated *sequential* loads stay legal — the entry pops when each load completes; only active re-entrancy is a cycle. Regression: suite section [115] (generated fixtures — mutual import raises + is try/catch-able, mutual load_file raises, no SIGSEGV). Full release + ASan/leak suites green (2625/2625, leak tally 0). Closes #496 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A mutual or self-referential
import(a→b→a) orload_file(a↔b) recursed throughvm_executeuntil the C stack overflowed — SIGSEGV,rc=139, uncatchable. The module cache is only populated after a load finishes, so a re-entrant load of a still-loading path missed the cache and recursed.Reproduced on v0.28.0:
Fix
A per-
EigsStatein-flight load stack (eigs_loading_active/enter/leave) records paths whose load is currently on the C stack:importopcode checks it on cache-miss;load_file(which has no cache and re-executes every call) keys on the canonicalrealpath;import→load_file→import) is caught.On a cycle the loader raises a catchable
ioerror instead of recursing:Repeated sequential loads of the same file stay legal — the entry pops when each load completes; only active re-entrancy is a cycle. Diamond imports (a→c, b→c) still resolve
conce via the cache.Tests
New suite section [115] (generated multi-file fixtures): mutual import raises + is
try/catch-able, mutualload_fileraises, none segfault.detect_leaks=1: 2625/2625, leak tally 0Closes #496
🤖 Generated with Claude Code