Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct Rg;
/// `--replace` path against memory amplification from attacker-controlled
/// replacement text combined with many matches (TM-DOS-RG-REPLACE).
const RG_MAX_REPLACEMENT_OUTPUT_BYTES: usize = 1_048_576;
const RG_MAX_JSON_CONTEXT_EVENTS: usize = 100_000;

struct RgOptions {
patterns: Vec<String>,
Expand Down Expand Up @@ -5402,6 +5403,12 @@ impl Builtin for Rg {
}
}
}
if context_lines.len() > RG_MAX_JSON_CONTEXT_EVENTS {
return Ok(ExecResult::err(
"rg: too many JSON context events (output capped)\n".to_string(),
2,
));
}
if context_lines.is_empty() {
for &mat in &matches {
write_rg_json_multiline_match(
Expand Down Expand Up @@ -5833,6 +5840,12 @@ impl Builtin for Rg {
}
}
}
if context_lines.len() > RG_MAX_JSON_CONTEXT_EVENTS {
return Ok(ExecResult::err(
"rg: too many JSON context events (output capped)\n".to_string(),
2,
));
}
if context_lines.is_empty() {
for &line_idx in &match_lines {
write_rg_json_match(
Expand Down
Loading