Repository navigation
fix(tools): harden apply_patch, fff, and exec tools - #363
Merged
Merged
Conversation
Make apply_patch tolerate the patches models actually emit (wrapped markers, blank context lines, addition-only hunks, CRLF, Move to, End of File, Change File, @@ location hints). Cap fff results and queries, reuse the shared index, strip credentials from exec_command, and refuse unbounded huge-file reads.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
Make apply_patch tolerate the patches models actually emit (wrapped markers, blank context lines, addition-only hunks, CRLF, Move to, End of File, Change File, @@ location hints). Cap fff results and queries, reuse the shared index, strip credentials from exec_command, and refuse unbounded huge-file reads.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Make apply_patch tolerate the patches models actually emit (wrapped markers, blank context lines, addition-only hunks, CRLF, Move to, End of File, Change File, @@ location hints). Cap fff results and queries, reuse the shared index, strip credentials from exec_command, and refuse unbounded huge-file reads.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Make apply_patch tolerate the patches models actually emit (wrapped markers, blank context lines, addition-only hunks, CRLF, Move to, End of File, Change File, @@ location hints). Cap fff results and queries, reuse the shared index, strip credentials from exec_command, and refuse unbounded huge-file reads.
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.
Summary
apply_patchtolerate the patches models actually emit: wrapped*** Begin/End Patchmarkers, blank context lines, addition-only hunks (append, not prepend), CRLF preservation,*** Move to:,*** End of File,*** Change File:, and@@location hints.resolve_write_pathso confinement matcheswrite_file, and cap the patch argument at 8 MB.fffind/ffgrepmax_results(200) and query length (512), reject blank queries, and reuse the shared index on a cache-miss race.exec_commandchildren, refuse login shells, and setkill_on_drop.read_fileof files over 2 MB, and checkview_imagesize before reading the bytes.Why
Models wrap patches in markdown, omit the leading space on blank hunk lines, emit addition-only hunks that were prepended, and use official format features (
Move to,End of File) that the parser treated as unknown.fffind/ffgrepacceptedu32::MAXresults.exec_commandinherited provider API keys and allowed login shells that re-export them.Test plan
cargo test --package forge-tools --package forge-search --package forge-core --lib --lockedcargo clippy --package forge-tools --package forge-search --package forge-core --all-targets --locked -- -D warningscargo fmt --all -- --check