Repository navigation
Do not panic on a repeated or leading no-newline marker - #75
Merged
Merged
Conversation
iter_lines_handle_nl asserted that the held line ends in a newline before stripping it, so a second consecutive marker aborted, and a marker with no line before it hit an unconditional panic. Both are reachable from parse_patch, which returns Result.
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.
parse_patchpanics on two shapes of\ No newline at end of file, even though it returnsResult<_, Error>.src/unified.rs:128initer_lines_handle_nl:The first marker strips the trailing newline from the held line. A second consecutive marker
then re-asserts on the line that no longer has one:
A marker as the first line takes the other branch:
Both fire in debug and release —
assert!is not debug-only.parse_patch(src/unified.rs:476)and
parse_patches(src/unified.rs:1165) both returnResult, so a caller handling malformedinput correctly still aborts.
Change
Neither case has anything to strip, and neither is fatal: a repeated marker is redundant, and a
leading one refers to nothing. Using
strip_suffixmakes both a no-op without changing the publicsignature, which is
impl Iterator<Item = &[u8]>and cannot carry an error:That preserves the documented behaviour — a line that had no terminating newline is produced
without one — and the existing
test_iter_lines_handle_nlstill passes unchanged.Verification
Two regression tests added next to it. Red with only the
iter_lines_handle_nlbody reverted (bothpanic at
src/unified.rs:130), green with the change: 254 passed, 0 failed plus the 2 doctests.
cargo fmt --checkclean.Found by driving the five targets in
fuzz/fuzz_targets/directly —grep -rniE "fuzz" .github/workflows/returns nothing, so the harness added in #65 has never run. 200,000 mutatedinputs produced 86 panics, and a run with a location-counting hook attributed every one to this
single site.
Adjacent, not included here
src/unified.rs:1925and:1936computeself.orig_pos - 1unguarded.@@ -0,0 +1,3 @@— whatGNU diff emits for an added file, and which this repo parses in its own test at
src/apply.rs:729— makes that underflow: a debug panic, and in release it wraps so
shift_to_modreturnsSome(0)for every position.src/apply.rs:170and:274already write the same expression asorig_pos.saturating_sub(1). Happy to send that separately if you'd like it.Disclosure: prepared with AI assistance; I verified both reproductions, the red/green and the suite
runs myself.