fix(interpreter): Box::pin expand_word to prevent stack overflow in nested $()#1109
Merged
fix(interpreter): Box::pin expand_word to prevent stack overflow in nested $()#1109
Conversation
…ested $() Each command substitution level previously inlined the expand_word async state machine into the caller's stack frame. The state machine is large (many WordPart match arms with their locals) and at ~20-30 nesting levels the call stack overflows with SIGABRT. Fix by boxing two key futures: - expand_word: wraps the inner implementation in Box::pin so each call allocates its future on the heap instead of the parent's stack - execute_cmd_subst: new helper that Box::pin-s the command substitution body (state snapshot, command loop, state restore), keeping those large locals off the stack With both futures boxed, each nesting level uses constant stack space regardless of depth. The default max_subst_depth of 32 now completes without overflow (previously crashed at ~20). Closes #1089
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.
Summary
expand_wordand extractexecute_cmd_substhelper to prevent stack overflow from nested command substitutions$(...)level previously inlined the largeexpand_wordasync state machine into the caller's stack frame, causing SIGABRT at ~20-30 levelsmax_subst_depth) now completes safelyChanges
interpreter/mod.rs: convertexpand_wordfromasync fntofn -> Pin<Box<Future>>wrapper overexpand_word_inner; addexecute_cmd_substBox::pin-ed helper for the command substitution bodystack_overflow_regression_tests.rs: 2 tests exercising depth 32 and nested arithmetic substitutionspecs/006-threat-model.md: add TM-DOS-089Test plan
cargo test --test stack_overflow_regression_tests— 2 new tests pass (previously SIGABRT)cargo test --all-features -- --skip ssh_supabase— all passcargo clippy --all-targets --all-features -- -D warnings— cleanCloses #1089