Skip to content

feat(streaming): walk a whole R2004-family file behind one checkpoint - #312

Merged
DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-whole-walk
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-whole-walk

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

R2004Walker walks a whole R2004-family file behind one state and one self-contained checkpoint: the header, the page map and the section map fill a fixed section table, then every data page the page map lists is walked in page-map order, with its bytes tagged by section and offset. No page index is the caller's; a section's pages are accounted for against its section map references by count and digest. Refs #205, closes the checkpoint half of #207.

Spec reference

ODA v5.4.1 §4.1, §4.3–§4.6 walks only (no new format feature). Design per the integrator's sign-off on #207: pass A is the map walk (section table of at most 64 slots, SectionTableFull beyond; references counted and folded into a splitmix64 digest of page number, start offset and data size); pass B re-reads the page map (a map-walker pages-only mode that is never in its checkpoint) and walks each data page through the section walker, started from the page's checksummed header. At the end every section's seen count and digest must equal its reference count and digest (SectionDigest), so a page missing, walked twice, unlisted or in the wrong place is caught whatever order the page map holds them in; the digest is an integrity check, not a security boundary. One deviation from the sign-off, agreed there: a page's data size is its stored length (padded for stored sections, compressed for LZ77), so it is not bounded by the section size; bytes past the section's end are decoded and dropped.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features, cargo +1.85 check --all-features, cargo test --release --all-features (no test added or changed), check_invariants.py, spec_coverage.py --check, no_std.rs native and wasm32 with new bounds 2 * WINDOW + 8192 for the walker and its checkpoint.
  • Real files, E2E: tools/streaming/verify_file.py on the four canonical R2004-family fixtures, the 21 pinned nextgis files (321 pages, 306 sections) and a file it builds with its pages in section order, reversed and shuffled: every printed line and assembled byte equals an independent Python assembly and the legacy read_section_payload; five fixed and 128 proptest schedules; fresh-process resume at every step of the R2018 fixture and about 80 stops of each of three real files and the built ones (all six stages, source reads and output concatenating exactly, section bytes equal after resume); bit flips at every byte and every truncation of a small checkpoint, 100 sampled of each for a walking one, a wrong identity and 50 resealed unreachable states rejected; six corruptions on the fixture and one real file per release band (both checksums, page type, a section the map does not describe, a start offset the map does not list, a data size) and six on the built file (page missing from the page map, listed twice, an unlisted page of a known and of an unknown section, 65 sections, an encrypted section) end in their named error.
  • Cross-runtime: the wasm32 kernel gains resume_file and run_file; about 60 native DWGF checkpoints per file restored in the kernel from the checkpoint alone (no page index, no section list) finish equal to the native resume at kernel read sizes 1, 7, 64 and 256; the kernel's own checkpoint at the same step is byte-identical to the native one in every case (55 to 62 per file) and resumes natively; sampled bit flips and a wrong identity are refused by the kernel. Under node, not a browser.
  • Regression: verify_maps.py and verify_sections.py pass unchanged on the modified map walker (new pages_only field, never serialized). Also run locally with the 7 further ACadSharp drawings (625 pages, 423 sections including shuffled-build files): same result.
  • Wired into the Streaming E2E job (file-evidence.json, wasm-evidence.json).

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported. This matters because dwg-rs is Apache-2.0 and must remain compatible.

My contribution is based on:

  • The ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1);
  • Measurement of the pinned public corpus (no algorithm-description comments of other projects were read for this change).

R2004Walker is the map walker and the section walker behind one state and
one checkpoint, for a caller with no page index. A walker with fixed state
cannot hold the page index, so it does not walk in section order. Pass A
is the map walk: each section description goes into a fixed table of at
most 64 slots (SectionTableFull beyond) and is handed to the caller, and
each page reference is counted and folded into a digest. Pass B reads the
page map again entry by entry and walks every data page it lists in the
order it gives: the page's checksummed header names its section and its
place in it, which is all the section walker needs, so nothing but the
table is needed. Bytes come out tagged with their section and offset and
the consumer scatters them. At the end every section's pages must be the
pages its references listed: the count and the digest (a wrapping sum of a
splitmix64 mix of page number, start offset and data size) of the
references equal those of the pages the page map held. A page missing,
walked twice, unlisted or in the wrong place changes it, whatever order the
page map holds them in; it is an integrity check on checksummed headers,
not a security boundary. A page's data size is the length of its stored
bytes, so it is not bounded by the section's size; a padded last page's
bytes past the end are decoded and dropped.

R2004WalkCheckpoint (DWGF, about 100 KB: two decoder windows) holds the
table and the two walkers' checkpoints and is self-contained: restore needs
the source identity and nothing else, and requires a reachable state (both
walkers validated by their own restore, then the table, the stage against
the map walker's mode and refs left, and the page in hand against the
table). The map walker gains a pages-only mode (never in its checkpoint) for
the second pass.

stream_r2004_file is the entry point (--out writes sections sparsely and
prints section_done; --legacy assembles them with read_section_payload).
verify_file.py runs it on the four canonical R2004-family fixtures, the 21
pinned nextgis files (321 pages, 306 sections) and a file it builds with its
pages in section order, reversed and shuffled: every line and byte equals an
independent Python assembly and the legacy reader; five fixed and 128
proptest schedules; fresh-process resume at every step of the R2018 fixture
and about 80 stops of each of three real files and the built ones, all six
stages, source reads and output concatenating exactly; bit flips and
truncations, a wrong identity and 50 resealed forgeries rejected; six
corruptions per band and six on the built file ending in their named error.
The wasm32 kernel gains resume_file and run_file: about 60 native
checkpoints per file restored in wasm from the checkpoint alone finish
equal to the native resume, and the kernel's own checkpoint at the same
step is byte-identical to the native one in every case and resumes natively.
Both run in the required Streaming E2E job.

Refs #205, #207
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T14:48:56.524772Z d8e1d36 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23c2a269c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/streaming/checkpoint.rs Resolved
Comment thread examples/stream_r2004_file.rs Resolved
Comment thread examples/stream_r2004_file.rs Resolved
…ncate new section files on resume, escape section names

A DWGF checkpoint taken at Verify or Done omitted the map walker, and with
it the only copy of the verified file header, so header() went from Some to
None across a restore. Those stages now keep the header checkpoint alone
(a finished map pass has nothing to resume) and restore requires it.

stream_r2004_file opened the output file of a section described after a
resume without truncating it, so stale bytes in an older file survived in
the section's holes; a section described by this process now always starts
empty, and only files of sections described before the checkpoint are kept.

Section names went into the JSON lines unescaped, so a name with a quote or
a backslash, which the map walker admits, broke the output. The file,
sections and maps examples and the wasm kernel escape both characters.

verify_file.py checks that the header printed after a resume from every
stage equals the uninterrupted run's and starts every stop with stale
output in each section file; the built file names a section with a quote
and a backslash, which every verifier now reads back through json.loads.

Reported by the review on #312.
@DrunkOnJava
DrunkOnJava merged commit 9bd78a8 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-whole-walk branch October 26, 2026 15:03
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
… to what landed (#205, #206, #207) (#400)

The ledger stopped at the header and the R13-R2000 walk, and the README's
checkpoint contract described the header checkpoint alone and said full object
and decompression checkpoints remain open. Both now cover the ten checkpoint
kinds on main and the walkers of #240, #246, #260, #276, #299, #312, #333, #340
and #363, the perf series #360 to #366, and cite the evidence files of Streaming
E2E run 40532346151. What was not measured is marked NOT MEASURED.
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