Skip to content

unified: error on truncated hunk bodies instead of silent termination#61

Merged
jelmer merged 1 commit intomasterfrom
truncted-bodies
Apr 21, 2026
Merged

unified: error on truncated hunk bodies instead of silent termination#61
jelmer merged 1 commit intomasterfrom
truncted-bodies

Conversation

@jelmer
Copy link
Copy Markdown
Member

@jelmer jelmer commented Apr 21, 2026

iter_hunks used iter_lines.next()? inside the per-hunk body loop. When a hunk header declared more orig/mod lines than the input provided, the ? propagated the inner None as a None from the from_fn closure — which terminated iteration without recording the partial hunk and without returning an error. Callers couldn't tell "valid empty input" from "truncated patch", and miscounted ranges upstream were silently swallowed.

Replace the ? with an explicit None match that returns PatchSyntax("Truncated hunk body"). Two regression tests cover both forms: a partial body and an EOF immediately after the header.

iter_hunks used `iter_lines.next()?` inside the per-hunk body loop.
When a hunk header declared more orig/mod lines than the input
provided, the `?` propagated the inner None as a None from the
from_fn closure — which terminated iteration without recording the
partial hunk and without returning an error. Callers couldn't tell
"valid empty input" from "truncated patch", and miscounted ranges
upstream were silently swallowed.

Replace the `?` with an explicit None match that returns
PatchSyntax("Truncated hunk body"). Two regression tests cover
both forms: a partial body and an EOF immediately after the
header.
@jelmer jelmer enabled auto-merge April 21, 2026 09:30
@jelmer jelmer merged commit 09d69c6 into master Apr 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant