Skip to content

feat(streaming): walk the R13-R2000 container with byte-demand states - #240

Merged
DrunkOnJava merged 1 commit into
mainfrom
feat/streaming-flat-walk
Oct 26, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
feat/streaming-flat-walk

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

streaming::FlatWalker continues the bounded byte-demand grammar from the §3.2 file header through the §9 header-variable and §10.1 class sections and the §23.1 object map, following every map entry to its §20.1 record and checking its framing, CRC, type and handle. Advances #205, #206, #207 and #210; none of them closes.

Spec reference

ODA Open Design Specification for .dwg files v5.4.1, §3.2 (file header and locators), §9 (header variables), §10.1 (classes), §20.1 (object records), §23.1 (object map). The framing enforced, confirmed on real files before coding (recorded in docs/streaming/audit.md):

  • §9 / §10.1 sections: start sentinel, RL size, data, RS CRC seeded 0xC0C1 over size and data, end sentinel; the locator size must be 38 plus the data size.
  • §23.1 map chunks: big-endian size counting its own two bytes (2 to 2032), entries, big-endian CRC over size and entries; a size-2 chunk ends exactly at the locator's end.
  • §20.1 records: MS size (at most two words), data, little-endian CRC over the MS bytes and data; then type (BS), the R2000 RL and the handle, which must equal the map's.

Commit contract (audit decision 7): index bytes are verified before anything is derived from them, so each map chunk is read twice (a CRC-only pass with no storage, then a decoding pass); payload is handed to the caller provisionally and committed only by the Section or Object step after its checks. Every mismatch is a typed terminal StreamError. State is fixed-size (464 bytes measured on aarch64, compile-time bounded at 512) with no allocation, and compiles in the no_std, no-allocator kernel natively and for wasm32-unknown-unknown. WalkCheckpoint (at most 256 bytes) embeds the header checkpoint, replayed on restore, and the walk cursors, which must form a reachable state over the verified locators.

The canonical R2000 fixture now frames its header-variable section and an empty class section, so the strict walk accepts it end to end.

Test plan

Measured on the rebased commit (one commit on main):

  • cargo run --release --example build_fixtures regenerates every fixture byte-identically to this commit.
  • python3 tools/streaming/check_invariants.py and both kernel builds (rustc ... tools/streaming/no_std.rs, native and --target wasm32-unknown-unknown).
  • python3 tools/streaming/verify.py (header acceptance, unchanged) and python3 tools/streaming/verify_walk.py target/debug/examples/stream_walk target/debug/examples/streaming_schedules: the canonical R2000 fixture and every R14 and R2000 file at nextgis/dwg_samples@ff05d5a (14 files, fetched by sha256 from tools/streaming/walk-corpus.json, never committed): 3,546 records. For each file the walk's whole output equals an independent Python framing parse and the legacy reader's handle-map walk (handle, offset, size, type, payload CRC-32); seven fixed chunk schedules reproduce it; 128 proptest schedules on three files. Fresh-process resume at every feed of the canonical file (104 stops) and 66 sampled feeds of line_R14 and line_2000: source reads and output of the two processes concatenate to the uninterrupted run's (no re-read, no duplicate output). 227 bit flips, 227 truncations and 14 resealed forgeries of a walk checkpoint rejected; 25 corruptions per file (flipped, resealed, truncated and short-transport) end in the named error with only the valid prefix committed.
  • fmt, clippy (-D warnings, all targets) and cargo doc -D warnings locally; the full OS/MSRV matrix runs in CI.
  • No new unit tests.

Not measured: a real R13 file, files larger than about 160 KB, and throughput.

CI note. The Streaming E2E job now fetches the 14 pinned nextgis R14/R2000 files by hash at run time. They are pins of the same ff05d5a commit the corpus-CI lane (#95) is pinning; the two manifests are to converge in that lane's PR. CLAUDE.md's "CI reads no real DWG file" stops being true when this lands (the coordinator is updating it).

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.

FlatWalker continues from the §3.2 file header through the §9
header-variable and §10.1 class sections and the §23.1 object map,
following every entry to its §20.1 record. Each transition declares its
exact offset and remaining demand; state is fixed-size (under 512
bytes, no allocation) and compiles in the no_std/wasm32 kernel.

Index bytes are verified before use: each map chunk is CRC-checked in
a storage-free pass, then re-read to decode entries and visit records.
Payload is handed to the caller provisionally and committed by the
Section or Object step after its size, CRC, sentinel, type and handle
checks. Every mismatch is a typed terminal error. WalkCheckpoint embeds
the header checkpoint (replayed on restore) and the walk cursors, which
must form a reachable state over the verified locators.

stream_walk is the entry point; --legacy prints the legacy reader's
handle-map walk in the same shape. verify_walk.py runs it on the
canonical R2000 fixture and every R14/R2000 file in the pinned
nextgis/dwg_samples commit (3,546 records): the output equals an
independent framing parse and the legacy reader, holds under fixed and
proptest chunk schedules, resumes in a fresh process at every feed of
the canonical file and 66 per real file with no source re-read or
duplicate output, and rejects 25 corruptions per file and every
corrupt, truncated or resealed-inconsistent checkpoint. It runs in the
required Streaming E2E job.

The canonical R2000 fixture now frames its header-variable section and
an empty class section, so the strict walk accepts it end to end.

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

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 🔄 Running since 2026-10-26T09:43:51.295524Z 6fe1598 PR opened
ℹ️ 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 enabled auto-merge (squash) October 26, 2026 09:44
@DrunkOnJava
DrunkOnJava merged commit 240f376 into main Oct 26, 2026
24 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-flat-walk branch October 26, 2026 09:48
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