fix(cli/mem): bound mem patch input at 4 MiB and error instead of truncating - #6475
Open
sanjay3290 wants to merge 2 commits into
Open
fix(cli/mem): bound mem patch input at 4 MiB and error instead of truncating#6475sanjay3290 wants to merge 2 commits into
sanjay3290 wants to merge 2 commits into
Conversation
Signed-off-by: Sanjay Ramadugu <sramadugu1@gmail.com>
Signed-off-by: Sanjay Ramadugu <sramadugu1@gmail.com>
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.
Fixes #6262.
mem patchread its diff withread_to_stringon stdin andfs::read_to_stringon--patch-file, with no bound. A patch larger than the NIP-44 value cap was accepted,silently cut down, and then reported back as a hunk-syntax error — so the user saw a
parse failure for a patch that was in fact well-formed, and had no signal that anything
had been dropped.
This bounds patch input at 4 MiB and errors instead of truncating.
read_patch_input(reader, limit)readslimit + 1bytes viaRead::takeand returnsa
CliError::Usagenaming the limit if the input exceeds it. Reading one byte past thelimit is what distinguishes "exactly at the limit" from "over it" without buffering the
whole oversized input.
read_patch_source(patch_path, limit)holds both input branches, so stdin and--patch-fileare bounded by construction andcmd_patchhas a single call site.The existing empty-stdin rejection is preserved; an empty
--patch-filestillpropagates to the caller as before.
patches, chaining
--base-hashthrough each result.No change to the existing result-size check after the patch is applied.
Six tests: exact limit accepted, over limit rejected with the limit in the message, a
diff larger than the NIP-44 cap but under 4 MiB still accepted, no truncation at any size,
and two
--patch-filecall-site tests through a tempfile.Verified locally at
cafb88e6con a clean tree:./scripts/run-tests.sh unit— exit 0cargo clippy --workspace --all-targets -- -D warnings— exit 0cargo fmt --all -- --check— exit 0Deletion probes, both compiling and both failing:
--patch-filebranch tofs::read_to_stringfailsread_patch_source_file_over_limit_errbuf.len() > limit + 1failsread_patch_input_never_truncates,read_patch_input_over_limit_err_contains_limitandread_patch_source_file_over_limit_err