fix: batch rg to avoid arg-length crash (audit H4) - #49
Merged
Conversation
run_rule and detect_stack passed every candidate file on one rg command line. On Windows (32767-char CreateProcess cap) this crashed at ~180 files with an uncaught OSError (WinError 206) that exited 1 — so a scanner crash masqueraded as 'findings present' and no checkpoint/report was written. detect_stack was worst: it passed ALL files regardless of per-rule globs. Fix: _batches() splits files so each rg command stays under a conservative 24000-char budget; _run_rg() runs the batches and maps OSError -> RuntimeError (caught by cmd_scan -> exit 2, the documented 'execution error'). Verified: a 400-file repo that crashed before now scans (exit 0); fixture unchanged (32). Added a _batches unit test.
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.
run_rule/detect_stackpassed every candidate file on onergcommand line. On Windows (32 KBCreateProcesscap) this crashed at ~180 files with an uncaughtOSErrorthat exited 1 — so a scanner crash looked like 'findings present' and no report was written.detect_stackwas worst (all files, ignoring per-rule globs).Fix:
_batches()keeps eachrgcommand under a 24 KB budget;_run_rg()mapsOSError→RuntimeError→ exit 2 (documented execution error). Verified: a 400-file repo that crashed before now scans (exit 0); fixture unchanged (32);_batchesunit test added. 24 pass.