Skip to content

rows: a trailer whose two sizes wrap past 2^64 is refused, not added unchecked - #2544

Merged
ashhart merged 2 commits into
ashhart:mainfrom
chadhurley25075-png:compass/rows-file-trailer-sum
Nov 8, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
chadhurley25075-png:compass/rows-file-trailer-sum

Conversation

@chadhurley25075-png

Copy link
Copy Markdown
Contributor

rows_file reads a store file's trailer with its magic, version, kind and name all checked, and its existing test already proves an aborted write leaves no file behind. This adds the one check that trailer was missing, in the same style.

What this changes

Before: rows_file.open checked payload + meta + 96 == end with plain u64 arithmetic. A trailer whose two sizes add up to the file's size only by wrapping passed it: in a Debug or ReleaseSafe build the addition panics while a store opens, and in the ReleaseFast native binary the file is taken as whole, so readState asks for a meta-sized allocation and the whole Rows.open fails with OutOfMemory over one bad file, instead of the documented behaviour of dropping a file that fails its check. After: the sum is checked with std.math.add, and a pair that wraps is RowsRead like any other trailer that does not match its file.

  • Issue: n/a; no open issue. One checked sum over bytes read from disk.
  • Stacked on: main (1a56448). One commit.
  • atc overlap --json (run 2026-11-08 03:2x CT against main): overlaps: [], no open pull request shares the file; one local worktree shares it, conflict: clean. complete: false with pullFilesLimit, pullFilesUnavailable, timeLimit, so the open-PR coverage was partial.

Checks on this head

  • Head commit: bfedfb3
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 116 and 116, 0 new (python3 tools/pr_check.py --base main: 0 errors, 1 advisory warning about the Unreleased line).
  • Tests run, with the command and pass, fail and skip counts: on an x86_64 Linux host with Zig 0.17.0, zig build -Dfixed-cpu test --test-timeout 10m exit 0 (the runner prints no pass/fail/skip summary on a green build; rows_file.zig's tests are reached through prompt_cache.rows). zig fmt --check build.zig zig and git diff --check clean. Run on this head, bfedfb3, after the rebase onto 1a56448 (test 210 s).
  • CI: not run yet on this head; I will read it once it runs and label anything that is not mine.
  • Not run, and why: test-golden and the Metal and CUDA device checks; the change is a check at file open and does not reach a kernel or a served token.

Receipt

n/a: the change decides which corrupt store file is refused at open; it does not reach inference, tokens or speed.

  • Main against branch: n/a, see above.
  • Boxes it reaches: any build that opens a rows store (--learn-conversations and the prompt cache's disk states).
  • New switch? none.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: n/a for a receipt; host tests above ran on x86_64 Linux, Zig 0.17.0.
  • Paths and platforms the change reaches, which I ran and which I could not: rows_file.open on every platform; host tests on Linux; Metal, CUDA and HIP builds not run.
  • Exactness: n/a.
  • Main against this branch, same machine and checkpoint: n/a.
  • Decode speed before and after: n/a.
  • Prompt speed before and after: n/a, the change cannot reach prompt processing.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The test alone on main: zig build -Dfixed-cpu test fails, the Debug test binary crashes on the overflowing addition, Build Summary 7558/7626 tests passed (64 skipped, 1 failed, 3 crashed); with the change it passes. No dependency to skip on.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

From Chad Hurley and Compass — Compass is our family's assistant; this change was found, fixed and tested on Claude Mythos 5.1.

@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thanks @chadhurley25075-png, this is a clean fix. The checked sum at zig/src/core/rows_file.zig:203 closes the wrap, and after it every later payload + meta sum is bounded by the file's size. The test that adds 2^63 to both sizes pins it down. We'll add the CHANGELOG line when it lands, so nothing more is needed here.

Optional, same family of bug, here or in a follow-up: zig/src/core/rows_store.zig:461 adds the trailer's at (a u32, not covered by either hash) to r.keying.lookahead in u32. A corrupt at near 2^32 panics there in a safe build before the name check. Widening it to @as(usize, s.at) + r.keying.lookahead would close it.

chadhurley25075-png and others added 2 commits November 8, 2026 17:48
…unchecked

rows_file.open checked `payload + meta + 96 == end` with plain u64 arithmetic. A
trailer whose two sizes add up to the file's size only by wrapping passed it: in
a Debug or ReleaseSafe build the addition panics while a store opens, and in the
ReleaseFast native binary the file is taken as whole, so readState asks for a
`meta`-sized allocation and the whole Rows.open fails with OutOfMemory over one
bad file. The sum is now checked, and a pair that wraps is RowsRead like any
other trailer that does not match its file.

The test writes a block file, adds 2^63 to both sizes in its trailer (their sum
is the file's size again, past 2^64) and expects open to refuse it; before this
change it panics on the overflow.
@ashhart
ashhart force-pushed the compass/rows-file-trailer-sum branch from bfedfb3 to dfa24fb Compare November 8, 2026 17:48
@ashhart
ashhart merged commit 91b6335 into ashhart:main Nov 8, 2026
3 of 9 checks passed
@ashhart

ashhart commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thank you @chadhurley25075-png. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to chadhurley25075-png/TensorFold that referenced this pull request Nov 8, 2026
ashhart added a commit that referenced this pull request Nov 8, 2026
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 8, 2026
ashhart added a commit that referenced this pull request Nov 8, 2026
ashhart added a commit that referenced this pull request Nov 8, 2026
@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

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.

2 participants