fix(interpreter): add max_subst_depth limit to prevent OOM from nested $()#1107
Merged
fix(interpreter): add max_subst_depth limit to prevent OOM from nested $()#1107
Conversation
…d $() Each command substitution level clones the full interpreter state (variables, arrays, functions, etc.), so memory grows as depth × state_size. Previously, command substitution shared the function depth counter (max_function_depth=100), which allowed deep nesting to exhaust memory. Add a dedicated max_subst_depth limit (default 32) with its own counter. This bounds memory consumption from nested $(...) chains while keeping the function depth limit independent. - Add max_subst_depth field to ExecutionLimits (default 32) - Add subst_depth counter to ExecutionCounters with push_subst/pop_subst - Switch CommandSubstitution handler to use subst depth tracking - Harden arithmetic_fuzz target with tighter limits - Update blackbox_security_tests to set max_subst_depth - Add regression tests with fuzz crash input from #1088 - Add TM-DOS-088 to threat model Closes #1088
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
max_subst_depthlimit (default 32) toExecutionLimitsto prevent OOM from deeply nested command substitutions$(...)level clones the full interpreter state — memory grows as depth × state_sizemax_function_depthcounter (default 100) was too generous for expensive state-cloning operationsarithmetic_fuzztarget with tighter resource limitsChanges
limits.rs: newmax_subst_depthfield,subst_depthcounter,push_subst/pop_substmethods,MaxSubstDeptherror variantinterpreter/mod.rs: switch both command substitution paths frompush_function/pop_functiontopush_subst/pop_substarithmetic_fuzz.rs: addmax_function_depth(10),max_subst_depth(5),max_stdout_bytes(4096),max_stderr_bytes(4096)blackbox_security_tests.rs: setmax_subst_depthintight_bash()anddos_bash()helperssubst_depth_limit_tests.rs: 3 regression tests including decoded fuzz crash inputspecs/006-threat-model.md: add TM-DOS-088Test plan
cargo test --test subst_depth_limit_tests— 3 new tests passcargo test --test blackbox_security_tests— 78 tests pass (previously stack-overflowed)cargo test --all-features -- --skip ssh_supabase— all passcargo clippy --all-targets --all-features -- -D warnings— cleancargo fmt --check— cleanCloses #1088