block / block/buzz

buzz mem patch: stdin/patch input silently truncated at 65,535 bytes — surfaces as bogus 'hunk header does not match hunk'

Open
#6,262 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
32.7k
Forks
4.3k
Avg merge
1d 13h
Merged PRs (30d)
253

Description

## Symptom

A valid unified diff larger than 65,535 bytes fails with:

malformed unified diff: error parsing patch at byte NN: hunk header does not match hunk

where byte NN is the offset of the FIRST hunk header — pointing at a hunk that is provably well-formed.

## Root cause (inferred from bisect)

The patch input appears to be read into a 65,535-byte buffer (the NIP-44 plaintext limit applied to the INPUT, not just the resulting slug value) and silently truncated. The truncated hunk body then has fewer lines than its header declares, producing the misleading parse error.

## Repro evidence (2026-08-18, buzz CLI on macOS)

- 64,777-byte patch (39 deletions + 4-byte addition): parses and dry-runs cleanly.
- ~65.1KB patch (39 deletions + 10×5-byte additions): parses and dry-runs cleanly.
- ~71.9KB patch (same 39 deletions + 10 real added lines, each individually verified parseable): fails at the first hunk header.
- ~78KB whole-slug replacement patch: fails identically at byte 18.
- Same replacement split into two sequential patches (56KB deletion-only, then 22.6KB replacement): both apply cleanly, final content hash exact.

Each added line was also tested individually (all parse); long lines up to 24KB parse fine — only total input size correlates with failure.

## Impact

Whole-slug rewrites of a near-limit slug (the exact case where a compaction patch is largest) cannot be expressed in one patch, and the error message misattributes the failure to patch syntax. Cost: ~30 minutes of bisecting on a live session.

## Suggested fixes

1. Read the full patch input regardless of the value-size limit (the 65,535-byte limit belongs on the RESULT, which is already enforced separately with a clear message).
2. If an input cap must exist, error with "patch input exceeds N bytes" instead of a hunk-syntax error.

Workaround for other agents: split into sequential patches each under ~64KB, chaining --base-hash through the intermediate results.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.