Skip to content

fix: refuse overflowing tile geometry and oversized sidecars - #1

Merged
HaoZeke merged 3 commits into
mainfrom
fix/merkle-bounds
Nov 16, 2026
Merged

HaoZeke merged 3 commits into
mainfrom
fix/merkle-bounds

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Bounds fixes for tile trees built from untrusted sizes.

  • split_point doubled until split * 2 overflowed. A checkpoint size above 2^63 panicked in debug and spun in release before any tile was read.
  • perfect shifted 1u64 << height for heights of 64 or more and used saturating_add, so an overflowing span could pass the bounds check.
  • The sidecar writer cast the pair count and key length to u16, so 65536 pairs were stored as 0. A bundle wider than 256 wrapped the one-byte offset. The writer now refuses values the format cannot hold.
  • A second, naive RFC 9162 tree checks proof shapes at the edge sizes (0, 1, 2, 4, 5, 8, 9, 16, 17), and flipped, truncated or extended proofs are rejected.

Roots for 1 to 8 leaves match an independent SHA-256 implementation of section 2.1. fmt, clippy, the workspace tests, the doc tests, cargo publish --dry-run, towncrier build --draft and the docs build pass. Each commit has a towncrier fragment.

A tree wider than 2^63 made split_point panic in debug and loop in
release. A perfect subtree whose span does not fit in a u64 is refused.
The u16 pair count and key length were truncated, so a wide key set
was written as a sidecar no reader could decode. A bundle wider than
256 entries is refused because the offset is one byte.
Sizes 0, 1, 2 and either side of a power of two are compared with a
second implementation of the RFC 9162 recursion, and a flipped,
truncated or extended proof is rejected.
@HaoZeke
HaoZeke merged commit 4332dd8 into main Nov 16, 2026
6 checks passed
@HaoZeke
HaoZeke deleted the fix/merkle-bounds branch November 16, 2026 05:14
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