Skip to content

[rntuple] Verify envelope checksums - #129

Open
sathabbott wants to merge 3 commits into
nsmith-:mainfrom
sathabbott:fix/117-envelope-checksums
Open

sathabbott wants to merge 3 commits into
nsmith-:mainfrom
sathabbott:fix/117-envelope-checksums

Conversation

@sathabbott

Copy link
Copy Markdown
Collaborator

🤖 AI generated content

Fixes #117. Depends on #124 (the tests cover rntuple/compressed.root, whose envelopes are compressed); until #124 merges, this PR also shows its commit.

  • REnvelope.read verifies the envelope's XXH3-64 over [0, length − 8) of the uncompressed envelope. The length includes the checksum and the checksum covers everything before it (root-io-spec ERRATA 5, checked against ROOT's VerifyXxHash3, RNTupleSerialize.cxx:934). Unknown trailing bytes are included, as Notes on Backward and Forward Compatibility requires ("must include both known and unknown contents"). A mismatch raises ValueError: <Envelope> checksum mismatch: stored …, computed ….
  • REnvelopeLocator.read_from: a stored size larger than the uncompressed length now raises. RNTuple decompression tests equality (root-io-spec NOTES 2, RNTupleZip.hxx:106-113): equal means raw, smaller means compressed, larger is an error. Before, it tried to decompress that case.

The existing cross-checks (the footer's and page lists' headerChecksum against the header's) stay.

Tests (tests/test_rntuple_envelopes.py):

  • every header, footer and page-list envelope of all 11 root-io-spec RNTuple fixtures verifies, compressed ones included;
  • in rntuple/anchor.root, flipping the case of the n of ntpl (offset 288, inside the header envelope at 268–508) still parses but raises the checksum mismatch; so does a flipped byte of the stored checksum;
  • a stored size larger than the length raises.

Without the change, 3 of these fail. Full suite: 411 passed, 61 skipped, 50 xfailed (on top of #124).

Assisted-by: claude-code:claude-opus-5-5

root-io-spec moves from 9c3f776 (2026-09-18) to c65c464 (2026-09-24), 68
commits. It still pins ROOT 6.40.04 (1211eda), the latest stable release,
so the tracked RNTuple specification (v1.0.2.1) is the same document.

It adds three RNTuple fixtures, all of which read:
- rntuple/compressed: the only compressed anchor and envelopes in the corpus
- rntuple/map: page locators that share byte ranges
- rntuple/attributes: linked attribute sets

Four new non-RNTuple fixtures fail. Each is listed in EXPECTED_FAILURES
with its exact error and the issue that tracks it:
- classes/roofit: nsmith-#71
- serialization/pointer-collection: nsmith-#105
- serialization/unframed-records: nsmith-#123, nsmith-#101
- written/two-versions: nsmith-#22

Assisted-by: claude-code:claude-opus-5-5
Every RNTuple envelope ends with an XXH3-64 checksum. rootfilespec read it
and compared stored checksums with each other, but never hashed the bytes,
so a corrupted header, footer or page list parsed without complaint.

REnvelope.read now checks the checksum over [0, length - 8) of the
uncompressed envelope: the length includes the checksum, and the checksum
covers everything before it (root-io-spec ERRATA 5, checked against ROOT's
VerifyXxHash3, RNTupleSerialize.cxx:934). Unknown trailing bytes are
covered too, as the spec's compatibility notes require.

REnvelopeLocator.read_from also refuses a stored size larger than the
uncompressed length. RNTuple decompression branches on equality (root-io-spec
NOTES 2, RNTupleZip.hxx:106-113), so that case is an error, where the code
used to try to decompress it.

Fixes nsmith-#117

Assisted-by: claude-code:claude-opus-5-5
The pre-commit mypy hook installs only pytest, numpy and tomli, so it cannot
find xxhash. bootstrap/compression.py already imports it the same way.

Assisted-by: claude-code:claude-opus-5-5
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.19%. Comparing base (3f43287) to head (b52867e).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #129      +/-   ##
==========================================
+ Coverage   91.82%   92.19%   +0.36%     
==========================================
  Files          37       37              
  Lines        2962     2971       +9     
==========================================
+ Hits         2720     2739      +19     
+ Misses        242      232      -10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

[rntuple] Envelope checksums are read but never verified

2 participants