Repository navigation
fix(sed): enforce grouped command depth at parse time - #1460
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 909528f | Commit Preview URL | Apr 25 2026, 01:31 AM |
chaliy
force-pushed
the
2026-04-24-fix-sed-nesting-validator-bypass
branch
from
April 25, 2026 01:30
757caea to
909528f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
chaliy
added a commit
that referenced
this pull request
May 30, 2026
### Motivation
- The flat precheck `validate_group_nesting` can misinterpret an `s` in
non-substitution contexts and undercount `{`/`}` causing the parser to
recurse past `MAX_GROUP_NESTING_DEPTH`.
- Prevent unbounded recursion/stack overflow by ensuring the parser
itself never recurses past the max depth even if the precheck is
bypassed.
### Description
- Add an explicit recursion depth guard in
`parse_sed_command_with_depth` for the `'{`' branch that returns an
error when `depth + 1 > MAX_GROUP_NESTING_DEPTH` (file:
`crates/bashkit/src/builtins/sed.rs`).
- Keep the existing `validate_group_nesting` precheck but add the
parser-level hard guard so bypasses cannot trigger unbounded recursion.
- Add regression test
`test_sed_grouped_command_nesting_depth_limit_with_address_bypass_shape`
that exercises the `/s<delim>/`-shaped address bypass and asserts a
depth-limit error (file: `crates/bashkit/src/builtins/sed.rs` tests).
### Testing
- Ran `cargo fmt --all` which completed successfully.
- Ran `cargo test -p bashkit
test_sed_grouped_command_nesting_depth_limit -- --nocapture` which
executed the existing depth-limit test and the new regression test and
both passed.
- Ran the crate test run (unit test suite invoked during the command
above) and observed the two modified/added tests pass with no
regressions in the executed test set.
------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_69eb99e1c918832bbae9de27f473a00b)
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.
Motivation
validate_group_nestingcan misinterpret ansin non-substitution contexts and undercount{/}causing the parser to recurse pastMAX_GROUP_NESTING_DEPTH.Description
parse_sed_command_with_depthfor the'{' branch that returns an error whendepth + 1 > MAX_GROUP_NESTING_DEPTH(file:crates/bashkit/src/builtins/sed.rs).validate_group_nestingprecheck but add the parser-level hard guard so bypasses cannot trigger unbounded recursion.test_sed_grouped_command_nesting_depth_limit_with_address_bypass_shapethat exercises the/s<delim>/-shaped address bypass and asserts a depth-limit error (file:crates/bashkit/src/builtins/sed.rstests).Testing
cargo fmt --allwhich completed successfully.cargo test -p bashkit test_sed_grouped_command_nesting_depth_limit -- --nocapturewhich executed the existing depth-limit test and the new regression test and both passed.Codex Task