Repository navigation
fix(rg): reject empty pattern with --only-matching - #1649
Merged
chaliy merged 1 commit intoMay 24, 2026
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 150a0ad | Commit Preview URL | May 23 2026, 09:15 AM |
chaliy
force-pushed
the
2026-05-22-fix-rg-o-memory-amplification-vulnerability
branch
from
May 22, 2026 09:09
d2d3a6b to
a2f802a
Compare
Prevent resource-exhaustion triggered by rg -o/--only-matching with an empty pattern, which produces zero-width matches at every UTF-8 boundary and can amplify builtin output allocations before interpreter truncation. Add a parse-time check in RgOptions::parse that returns Error::Execution when --only-matching is enabled and any provided pattern is empty.
chaliy
force-pushed
the
2026-05-22-fix-rg-o-memory-amplification-vulnerability
branch
from
May 23, 2026 09:15
a2f802a to
150a0ad
Compare
chaliy
added a commit
that referenced
this pull request
May 30, 2026
### Motivation
- Prevent resource-exhaustion triggered by `rg -o/--only-matching` with
an empty pattern, which produces zero-width matches at every UTF-8
boundary and can amplify builtin output allocations before interpreter
truncation.
### Description
- Add a parse-time check in `RgOptions::parse` (in
`crates/bashkit/src/builtins/rg.rs`) to return
`Err(Error::Execution("rg: empty pattern is not allowed with
--only-matching"))` when `--only-matching` is enabled and any provided
pattern is empty, and add a unit test
`test_rg_only_matching_rejects_empty_pattern` to cover `-o -e ''`.
### Testing
- Ran `cargo test -p bashkit rg_only_matching` and the targeted tests
including `test_rg_only_matching_rejects_empty_pattern` passed.
------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a0fa7290f08832b97de581326fb2b30)
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
rg -o/--only-matchingwith an empty pattern, which produces zero-width matches at every UTF-8 boundary and can amplify builtin output allocations before interpreter truncation.Description
RgOptions::parse(incrates/bashkit/src/builtins/rg.rs) to returnErr(Error::Execution("rg: empty pattern is not allowed with --only-matching"))when--only-matchingis enabled and any provided pattern is empty, and add a unit testtest_rg_only_matching_rejects_empty_patternto cover-o -e ''.Testing
cargo test -p bashkit rg_only_matchingand the targeted tests includingtest_rg_only_matching_rejects_empty_patternpassed.Codex Task