Skip to content

fix(cli): refuse near-no-op mem patch writes and -0,0 insertions into non-empty values - #7759

Open
innerline wants to merge 2 commits into
block:mainfrom
innerline:fix/mem-patch-near-noop-guard
Open

innerline wants to merge 2 commits into
block:mainfrom
innerline:fix/mem-patch-near-noop-guard

Conversation

@innerline

Copy link
Copy Markdown

Summary

buzz mem patch could apply a mis-targeted patch as a ~1-byte near-no-op and
still print a success-shaped receipt (new hash, plausible output), so the
corruption was invisible at a glance. Field case: a patch built for one slug
applied to another slug landed as a 1-byte append (@@ -1 +1 @@ with added
lines) — the write echoed a healthy-looking hash while the stored value
changed by a single byte, because append-style hunks with extra lines are not
context-validated.

Two mechanisms fixed:

  • @@ -0,0 @@ insertion hunks against non-empty values were accepted with
    no content check (diffy inserts at index 0 blindly). The empty-preimage path
    is now only valid against an actually-empty value.
  • Near-no-op guard: a patch result that is byte-identical to — or within
    one byte of — the current value is refused unless --allow-empty. This is
    the mis-targeted-slug / newline-drift signature; genuine small edits are
    unaffected.

Receipts are also hardened so a future misfire is visible at a glance:

  • mem patch write and dry-run receipts echo the target slug's byte delta
    (292→293 bytes (Δ+1)).
  • mem set receipts echo the written byte count.

Related issue

none found.

Testing

  • New unit tests bound to the production guard:
    near_noop_refusal_cases (identical value, ±1 byte, and trailing-newline
    drift refused; genuine growth and clearance allowed) and
    strict_position_rejects_dash00_insertion_into_nonempty.
  • cargo fmt -p buzz-cli -- --check, cargo clippy -p buzz-cli --all-targets, and cargo test -p buzz-cli mem all green (28 tests pass,
    including the two new ones).

… non-empty values

A mis-targeted `buzz mem patch` (patch built for one slug, applied to
another) could land as a 1-byte near-no-op with a success-shaped receipt
(2026-09-19 seat incident):

- `@@ -0,0 @@` insertion hunks were accepted against non-empty values with
  no content check — diffy inserts at index 0 blindly. The empty-preimage
  path is now only valid against an actually-empty value.
- A patch result that is byte-identical to or within one byte of the
  current value is refused unless --allow-empty (mis-targeted-slug /
  newline-drift signature).
- Write and dry-run receipts now echo the target slug's byte delta
  (292→293 bytes (Δ+1)) so mis-targeted writes are visible at a glance;
  mem set receipts echo the written byte count.

Signed-off-by: innerline <innerline@me.com>
…op-guard

Signed-off-by: innerline <innerline@me.com>
@innerline
innerline requested a review from a team as a code owner September 19, 2026 17:35
@github-actions

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 4ee9f8b35a612b5c83459af2fcee9f77000a29f6...58798ef3d9c5013aa59e760876ead21b75e8cadd.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review 58798ef3d9c5013aa59e760876ead21b75e8cadd to authorize a new review.
Any previous review applies only to its recorded range.

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