Skip to content

fix(rg): reject empty pattern with --only-matching#1649

Open
chaliy wants to merge 1 commit into
mainfrom
2026-05-22-fix-rg-o-memory-amplification-vulnerability
Open

fix(rg): reject empty pattern with --only-matching#1649
chaliy wants to merge 1 commit into
mainfrom
2026-05-22-fix-rg-o-memory-amplification-vulnerability

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 22, 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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 22, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 150a0ad Commit Preview URL May 23 2026, 09:15 AM

@chaliy chaliy force-pushed the 2026-05-22-fix-rg-o-memory-amplification-vulnerability branch from d2d3a6b to a2f802a Compare May 22, 2026 09:09
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 chaliy force-pushed the 2026-05-22-fix-rg-o-memory-amplification-vulnerability branch from a2f802a to 150a0ad Compare May 23, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant