Commit 0c90959
authored
fix(rg): bound --colors parsing and sanitize invalid spec echo (#1782)
### Motivation
- The new `--colors` parser previously collected all colon-separated
fields into a `Vec`, allowing an attacker-controlled spec with many
delimiters to amplify allocations and trigger memory pressure or OOM.
- Error diagnostics echoed the full untrusted spec, risking large
diagnostic allocations and information amplification.
### Description
- Replace `spec.split(':').collect()` with bounded parsing using
`splitn(4, ':')` and validate fields incrementally to avoid allocation
amplification.
- Add `MAX_COLOR_SPEC_LEN` to reject overly long `--colors` inputs
early.
- Introduce `invalid_color_spec_error` to truncate and sanitize echoed
specs in error messages (limits echoed chars with `...`).
- Add two focused unit tests:
`colors_rejects_too_long_spec_with_truncated_echo` and
`colors_rejects_extra_delimiters_without_split_collect_amplification` to
cover rejection and diagnostic truncation.
### Testing
- Ran the focused tests with `cargo test -p bashkit colors_rejects`, and
both new tests passed.
- The package test run that executed these tests reported `2 passed; 0
failed` for the new cases and completed the crate test run successfully
(other tests were filtered as usual).
------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a13b309e0dc832baa49b1e8cc9b0c8d)1 parent ed919a7 commit 0c90959
1 file changed
Lines changed: 53 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
202 | 212 | | |
203 | 213 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 214 | + | |
| 215 | + | |
208 | 216 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
214 | 222 | | |
215 | 223 | | |
216 | 224 | | |
| |||
222 | 230 | | |
223 | 231 | | |
224 | 232 | | |
225 | | - | |
| 233 | + | |
226 | 234 | | |
227 | 235 | | |
228 | 236 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 237 | + | |
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
| |||
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
252 | 267 | | |
253 | 268 | | |
254 | 269 | | |
| |||
6093 | 6108 | | |
6094 | 6109 | | |
6095 | 6110 | | |
| 6111 | + | |
| 6112 | + | |
| 6113 | + | |
| 6114 | + | |
| 6115 | + | |
| 6116 | + | |
| 6117 | + | |
| 6118 | + | |
| 6119 | + | |
| 6120 | + | |
| 6121 | + | |
| 6122 | + | |
| 6123 | + | |
| 6124 | + | |
| 6125 | + | |
| 6126 | + | |
| 6127 | + | |
| 6128 | + | |
| 6129 | + | |
| 6130 | + | |
6096 | 6131 | | |
6097 | 6132 | | |
6098 | 6133 | | |
| |||
0 commit comments