Repository navigation
fix(grep): bound recursive searches and skip directory cycles - #2619
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 54471aa | Commit Preview URL Branch Preview URL |
Oct 08 2026, 01:32 AM |
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.
What changed
Recursive grep skips symlinks resolving to an ancestor, scans one file at a time, and stops traversal when
-qfinds a match. Traversal, retained directory/index paths, and file input use the existing shared execution budget and live-byte leases. Sibling aliases remain independent searches. Canonical resolution is shared withfind; diagnostics preserve GNU wording and a UTF-8-safe 1 KiB cap.Why
Fixes Codex Security finding
commit:882c2e7c8e488191b9d8fb8bb341118e: two self-links could exponentially amplify traversal and retained copies of the same file before scanning. Per-lookup symlink hop limits did not bound the overall walk.Before / After
A safe single-link regression (
mkdir /d; echo x > /d/f; ln -s . /d/a; grep -R x /d) printed the same file 41 times before the fix. It now prints/d/f:xonce and warnsgrep: /d/a: warning: recursive directory loop, exiting 0. All three initial tests failed before the fix (cycle revisits, traversal work, and live file admission).The reported two-link layout now completes:
grep -Rq x /dreturns 0; a nonmatching search returns 1 with one warning per cyclic link. No resource-exhausting unpatched two-link run was executed. GNU grep 3.11 comparison: 104/104 cases match, including the new cycle and sibling-alias cases.Validation:
cargo test -p bashkit --lib --bins --tests --features http_client,ssh,sqlite: 4,753 passed; all nine new resource/cycle regressions passed.cargo deny check,cargo vet --locked, 150 script tests, OKF, docs, workflow, and capability checks passed.just benchpassed (96 cases, zero errors, 100% output match).Local
just pre-prandjust testhit an unrelated macOS stack overflow inmisconfig_huge_ast_depth_still_safewhen the whole workspace combines runtime features. The exact test also aborts on untouched mainf286bf332c6eadcda068c645077432d7da7f729d; it passes with default features and in the feature slice above. Its test and limits are unchanged. Required PR CI must pass before merge.Risk
Medium: resource limits now apply during recursive search, so oversized searches can terminate earlier. Traversal order remains deterministic files-first/name order (the existing GNU readdir-order limitation). Host/custom filesystem backends retain responsibility for concurrent read allocation; VFS file admission occurs before cloning contents.
Checklist