Skip to content

feat(streaming): walk the R2004 page map and section map with byte-demand states - #276

Merged
DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-r2004-maps
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
feat/streaming-r2004-maps

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

streaming::R2004MapWalker walks the R2004-family §4.4 section page map and §4.5 section map with byte-demand states on the §4.7 decoder, checksum-verifying each system page before deriving anything from it and committing one record per step. Advances #205 (R2004+ container walk) and #207 (combined walk checkpoints); neither closes.

Rests on #260 (the §4.1 header grammar), #255 and #266 (real page checksums in the canonical fixtures), all on main.

Spec reference

ODA Open Design Specification for .dwg files v5.4.1: §4.2 (section page checksum), §4.3 (system page header and two-stage checksum), §4.4 (section page map; addresses accumulate from 0x100; gap entries carry four more longs), §4.5 (section map header and descriptions, page references), §4.7 (decoder).

Each system page is read twice, as the flat walk reads an object-map chunk twice (audit decision 7): a checksum pass that keeps nothing, then a decode pass. demand() returns Read (source bytes, at most 64 ahead of the decoder), Pump (output already decoded; no source bytes) or Done, so a compressed byte that expands into several records still yields one record per step. Checks enforced, each measured on every real file and the fixtures first: system page type, compression 2 and extent; page sizes non-zero multiples of 0x20; the page map's own entry at the header's address and large enough; an entry for the section map id; section map header (count, 2, 0x7400, 0, …); description compression (1, 2), encryption (0–2), page size, printable name; rising whole-page start offsets; exact decoded sizes. Not enforced, because real files don't follow them: sequential page numbers, the "unknown" longs, page extents inside the file. The walker holds no map; the index is the caller's. State bounded at WINDOW + 1024 in the no_std kernel (native and wasm32); R2004MapCheckpoint (DWGM, about 50 KB at most) embeds the header checkpoint (replayed) and the decoder checkpoint, and its cursors must form a reachable state.

Test plan

  • python3 tools/streaming/verify_maps.py target/debug/examples/stream_r2004_maps target/debug/examples/streaming_schedules: four canonical R2004-family fixtures and the 21 pinned nextgis R2004/R2010/R2013 files (from lz77-corpus.json). 371 page entries, 306 section descriptions, 321 section page references; every line equals an independent Python parse, every record the legacy section_map reader; five fixed schedules and 128 proptest schedules on three files reproduce it. Fresh-process resume at every step of synthetic_2018 (173) and line_2004 (316), sampled steps of line_2010 and line_2013: reads and output of the two processes concatenate to the uninterrupted run's. 606 bit flips, 606 truncations, a wrong identity and ten resealed unreachable states rejected for a mid-walk checkpoint. Eight corruptions per band (both checksums, page map type, page size off 0x20, page map off its own entry, section map header constant, a description field, a file cut inside the page map) end in their named errors; record faults get past the checksum by rewriting LZ77 literal bytes and resealing the page.
  • By hand: the local R2018 sample_AC1032.dwg (124 records equal to legacy).
  • check_invariants.py, kernel builds native and wasm32, fmt, clippy -D warnings, cargo doc -D warnings.
  • No new unit tests.

Not covered: data pages (§4.6) and section assembly, R2007, throughput.

Source-provenance declaration

Clean-room declaration. All code in this PR was written from scratch. The only sources consulted were this repository and the ODA's public Open Design Specification for .dwg files v5.4.1. No Autodesk SDK, ODA SDK (Drawings / Teigha), LibreDWG or other copyleft DWG implementation source, and no decompilation, was consulted. Spec citations are in the diff.

@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-r2004-maps branch from 5ac0c8e to 5a0cf63 Compare October 26, 2026 11:28
…mand states

R2004MapWalker continues from the §4.1 header into the two system pages:
the §4.4 section page map at the header's address, then the §4.5 section
map at the address its page-map entry gives. Each page is read twice, as
the flat walk reads an object-map chunk twice: a pass that checks the
§4.3 checksum and keeps nothing, then a pass through the §4.7 decoder
that commits one record per step. demand() distinguishes source reads
(at most 64 bytes ahead of the decoder) from pumps of output already
decoded, and poll_r2004_maps drives both. State is fixed (bounded at
WINDOW + 1024 in the no_std kernel, native and wasm32) and the walker
holds no map; R2004MapCheckpoint embeds the header and decoder
checkpoints and cursors that must form a reachable state.

Checked, because every real file and the fixtures agree: system page type,
compression and extent; page sizes non-zero multiples of 0x20; the page
map's own entry at the header's address; an entry for the section map
id; the section map header constants; description flags, page size and
name; rising whole-page start offsets; exact decoded sizes. Sequential
page numbers, the unknown longs and page extents inside the file are not
checked, since real files do not follow them.

stream_r2004_maps is the entry point; --legacy prints the legacy page map
and section info in the same shape. verify_maps.py runs it on the four
canonical R2004-family fixtures and the 21 pinned nextgis R2004, R2010
and R2013 files (371 pages, 306 sections, 321 section pages): equal to an
independent Python parse and the legacy reader under fixed and 128
proptest schedules; fresh-process resume at every step of two files and
sampled steps of two more with no read beyond the two designed passes;
bit-flipped, truncated, wrong-identity and resealed checkpoints rejected;
eight corruptions per release band, including record faults reached past
the checksum by rewriting LZ77 literal bytes and resealing, each ending
in its named error. It runs in the required Streaming E2E job.

Refs #205, #207
@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-r2004-maps branch from 5a0cf63 to fb3949a Compare October 26, 2026 11:52
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review October 26, 2026 11:52
@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-26T12:06:26.549125Z d2de785 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: fb3949a34a

ℹ️ 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/r2004_maps.rs Resolved
With every section record read, record_need is zero and the walker
decoded into an empty slice to reach the terminator. If the section
count understated the records, the decoder still had literal or copy
output to give, made no progress into that empty slice, and every demand
stayed Pump: the walk never ended. With no record open, the page must
already have produced its declared size; otherwise it is MapLength at
once.

verify_maps.py adds a section count one short and a count of zero,
reached past the checksum by rewriting the literal count byte and
resealing; both end in MapLength on the canonical R2004 fixture and one
file per release band. The verifier's per-run timeout drops to 120 s so
a hang fails fast.

Reported by the review on #276.
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 12:07
@DrunkOnJava
DrunkOnJava merged commit 1fc1a50 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-r2004-maps branch October 26, 2026 12:14
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