Skip to content

feat(streaming): assemble R2004 sections from their data pages with byte-demand states - #299

Merged
DrunkOnJava merged 1 commit into
mainfrom
feat/streaming-r2004-sections
Oct 26, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
feat/streaming-r2004-sections

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

R2004SectionWalker walks one section's data pages (§4.6) after the page map and section map walk: it checks each page's masked header and both checksums, runs the stored bytes through the streaming LZ77 decoder (or copies them for a stored section) and hands out the assembled section in order, with exact byte demand per transition, fixed state and a checkpoint that resumes in a fresh process. Refs #205, #207.

Spec reference

ODA v5.4.1 §4.5 (section map), §4.6 (data pages), §4.2 (page checksum), §4.7 (LZ77). A format finding: the §4.6 header is not laid out as section_map::DataPageHeader labels it (start offset is 8 bytes at 0x10, the header checksum is at 0x18 seeded with the data checksum at 0x1C, and 0x0C is the page's size on disk, not the decompressed size). Measured on all 580 data pages of the 28 pinned R2004-family drawings and the four canonical fixtures; table in ARCHITECTURE.md §7n, reproduced by examples/probe_data_page_header.rs --strict (now a step of the Corpus job). section_map::DataPageHeader is left as it is.

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
  • python3 tools/streaming/check_invariants.py and tools/streaming/no_std.rs native and wasm32 (new size bounds WINDOW + 1024 for the walker and its checkpoint)
  • cargo test --release --all-features (existing suites; no test added or changed)
  • Real files, E2E: tools/streaming/verify_sections.py on the four canonical R2004-family fixtures, the 21 pinned nextgis files and a file it builds (holes, a zero page, a section with no page, stored and compressed sections, padded and exact last pages): every output line and assembled byte equals an independent Python assembly and the legacy reader (332 pages, 313 sections); 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 one, all six checkpoint kinds, source reads and output concatenating exactly; bit flips, truncations, a wrong identity and 20 resealed forgeries rejected; nine corruptions per band and five on the built file end in their named error. Wired into the Streaming E2E job (sections-evidence.json).
  • Also run locally on the 7 further ACadSharp drawings of the corpus cache (including sample_AC1018.dwg, whose AcDb:Template section declares bytes and lists no page): same result.

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).

@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-26T13:29:03.343609Z 115147d 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.

@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-r2004-sections branch from 8c81bc7 to 392aed1 Compare October 26, 2026 13:25
…yte-demand states

R2004SectionWalker takes one section description from the map walk, then
one page at a time from its caller, which holds the page index: demand()
answers NextPage between pages and begin_page(entry, reference) hands it
the page map's entry and the section map's reference. Each page is read
twice, as the system pages are: a pass that checks the masked 0x20-byte
header's own checksum, then every header field against what the caller
said, then the data checksum over the stored bytes, keeping nothing; then
a pass through the §4.7 decoder (or a copy, for a stored section) that
hands out section bytes in order, at most 256 per step. Nothing is
derived from a page before its checksums pass. Bytes no page covers (a
page starting further on, a section that lists no page) are handed out as
holes and read as zeros; a page at or past the section's end is walked
and checked and gives nothing; an encrypted section is refused. State is
fixed (bounded at WINDOW + 1024 in the no_std kernel, native and wasm32);
R2004SectionCheckpoint holds the section, the page in hand, the cursors
and the decoder, and restore requires a reachable state.

The §4.6 header is not laid out as section_map::DataPageHeader labels
it: the start offset is 8 bytes at 0x10, the header checksum is at 0x18
(§4.2 over the header, its field zeroed, seeded with the data checksum)
and the data checksum at 0x1C (seed 0), and 0x0C is the page's size on
disk, not the decompressed size. examples/probe_data_page_header counts
every reading on all 580 data pages of the 28 pinned R2004-family
drawings and the four fixtures (ARCHITECTURE.md §7n) and runs with
--strict in the Corpus job. The struct is left as it is.

stream_r2004_sections walks the maps and then every section, printing
lines that do not depend on the chunking; --out writes the sections and
--legacy assembles them with read_section_payload. verify_sections.py
runs it on the four canonical R2004-family fixtures, the 21 pinned nextgis
files and a file it builds (holes, a zero page, a section with no page,
stored and compressed sections): every line and byte equals an
independent Python assembly and the legacy reader (332 pages, 313
sections); 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 one, with all six checkpoint kinds and source reads
and output concatenating exactly; bit flips, truncations, a wrong identity
and twenty resealed forgeries rejected; nine corruptions per band and five
on the built file ending in their named error. It runs in the required
Streaming E2E job.

Refs #205, #207
@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-r2004-sections branch from 392aed1 to 115147d Compare October 26, 2026 13:26
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 13:30
@DrunkOnJava
DrunkOnJava merged commit 14b82c6 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-r2004-sections branch October 26, 2026 13:37
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
#309)

A lone diff3 base line (|||||||) reached main twice: CHANGELOG.md since
#80 and ARCHITECTURE.md with #299. Both are removed; the text around each
was complete. The PII guard job gains a step that fails on any committed
<<<<<<<, ||||||| or >>>>>>> marker line.
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