Skip to content

feat(streaming): stream the object records of an R2007 file (§20.1, #205) - #363

Merged
DrunkOnJava merged 4 commits into
mainfrom
feat/stream-r2007-objects
Oct 27, 2026
Merged

DrunkOnJava merged 4 commits into
mainfrom
feat/stream-r2007-objects

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Frames the object section of an R2007 (AC1021) file into records from the stream, in stream order, with no handle map or index held, as #333 does for the R2004 family. R2007ObjectWalker is the R2007 whole-file walker (#340) with AcDb:AcDbObjects singled out; every other section passes through as before. No record is committed from a page whose Reed-Solomon codewords, CRC-64s and checksum have not all passed.

An R2007 record is R2000's (RecordFormat::R2000: MS size, MS bytes of payload that open with a BS type, an RL size and the handle, then a CRC; no MC), so the framer is shared and unchanged. The R2007 split streams are not entered: the type and handle are in the front of the data stream, and the string stream (TV text) and handle stream (H references) at the back of the payload are bytes to the framer.

R2007ObjectCheckpoint (DWGQ) wraps the file walker's DWGR checkpoint, the section index, the framer's cursors and the not-yet-framed bytes (at most about 140 KB, bounded in the no_std build). Self-contained: restore needs the source identity and nothing else, and it restores in the wasm32 kernel and back, byte-identical. The framer's checkpoint fields moved into helpers shared with the R2004 DWGO, which is unchanged on the wire (its verifiers pass).

Behavior kept as decided earlier: a stretch of the object section that no page covers arrives as a Hole and is refused (ObjectsOrder); pages cannot arrive out of order because the file walk takes them in section-map order with rising offsets. A hole therefore ends the walk in a named error rather than being framed as zeros.

Evidence, from the pinned corpus (ARCHITECTURE.md section 7al):

  • all eight pinned R2007 drawings (7 nextgis, 1 ACadSharp): 2,237 records tile their sections exactly, every record CRC and every (handle, offset) of AcDb:Handles agrees, 34 records straddle a page boundary (the largest takes 150,151 bytes), and the same bytes read as R2010 records fail the first record's CRC in all 8;
  • the largest pinned R2007 drawing is sample_AC1021 at 1.06 MB; none larger is pinned or available locally, so a drawing over 1.1 MB is still unmeasured, as are an AutoCAD-written stored header, a non-zero CRC seed and an encrypted section (refused by design).

Spec reference

§20.1 (object record framing) on R2007; §19.1 and §7a for where the type, handle and the three streams sit. New dated section ARCHITECTURE.md 7al with its evidence table (arch.py check passes). No coverage-state change in docs/data/spec-coverage.tsv: no section's evidence moves, this adds a streaming reader for a layout the legacy reader already decodes. Part of #205.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings (one #[allow(clippy::large_enum_variant)] on the per-call R2007ObjectStep, which wraps the once-per-file 272-byte header step)
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • cargo +1.85 check --all-features (MSRV)
  • cargo test --release --all-features (existing suites only; no test added; built without LTO to fit the machine's CPU budget)
  • python3 tools/streaming/check_invariants.py (no std::, alloc::, Vec, ... in src/streaming/); tools/streaming/no_std.rs compiled natively and for wasm32-unknown-unknown, with new compile-time bounds for R2007ObjectWalker and R2007ObjectCheckpoint
  • python3 tools/maintainer/train/arch.py check and python3 tools/ci/spec_coverage.py --check
  • verify_r2007_objects.py (new; wired into streaming.yml with the new example): 8 pinned drawings and 8 built files, 2,496 records; every line equal to the independent Python framing (r2007_ref.py plus verify_objects.py's framer), the (handle, offset) pairs equal to an independent parse of AcDb:Handles, the 8 drawings' records equal to the legacy reader's; 5 fixed chunk schedules, a source that fails every other read, 128 proptest schedules on two files; 1,402 fresh-process resumes in every framer and walker stage (131 holding unframed bytes, 51 inside an MS, 50 inside a CRC, 247 inside a payload); 450 bit flips, 450 truncations, a wrong identity and 284 resealed unreachable states rejected; 34 corruptions each ending in its named error with exactly the valid records before it committed (including a flipped codeword of the object section's second, last and a middle page: 151, 161 and 807 records, then R2007Parity)
  • verify_wasm_r2007_objects.py (new): 701 native DWGQ checkpoints restored in the wasm32 kernel (run under node) finish equal to the native resume, at kernel read sizes 1, 7, 64 and 256; the kernel's own checkpoint is byte-identical to the native one in all 701 and the native build finishes it; 83 flipped or wrong-identity checkpoints refused by the kernel
  • The existing verify_objects.py (32 files, 8,027 records) and verify_wasm_objects.py still pass on this tree (the shared framer helpers)
  • The verifiers ran from release builds with overflow checks and debug assertions (the machine's CPU budget makes debug builds impractical); CI runs the debug builds. Reproduce: cargo build --locked --example stream_r2007_objects --example streaming_schedules, then python3 tools/streaming/verify_r2007_objects.py target/debug/examples/stream_r2007_objects target/debug/examples/streaming_schedules and python3 tools/streaming/verify_wasm_r2007_objects.py target/debug/examples/stream_r2007_objects.

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);
  • Public reverse-engineering notes, research papers, or blog posts cited inline;
  • Reading algorithm-description comments (not executable code) in permissively-licensed projects (MIT / Apache / BSD) to resolve spec ambiguities — disclose any such reading in this PR body so it can be recorded in CLEANROOM.md.

See CLEANROOM.md for the full allowed/forbidden source list and the honest scope of what "clean-room" means for this project.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the
Developer Certificate of Origin 1.1.
Specifically, I affirm that the contribution is my own work (or rightfully
licensed to me) and that it can be distributed under the project's Apache-2.0
license.

I will sign off commits with git commit -s when asked, which adds a
Signed-off-by trailer to the commit message asserting the DCO.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T04:39:33.222851Z e6f25e6 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.

)

R2007ObjectWalker is the R2007 whole-file walker with AcDb:AcDbObjects
singled out, as R2004ObjectWalker is for the R2004 family: the section's bytes
are framed in section order into records (MS size, payload, CRC, then type and
handle), with no handle map or index held, and every other section passes
through as the file walker reports it. No record is committed from a page
whose codewords, CRC-64s and checksum have not all passed.

An R2007 record is R2000's (RecordFormat::R2000: no MC, a BS type, an RL size,
the handle), so the framer is shared and unchanged. ARCHITECTURE.md 7al
measures it on the eight pinned R2007 drawings: 2,237 records tile their
sections exactly, every CRC and every (handle, offset) of AcDb:Handles agrees,
34 records straddle a page boundary, and the same bytes read as R2010 records
fail the first record's CRC.

R2007ObjectCheckpoint (DWGQ) wraps the file walker's DWGR checkpoint, the
section index, the framer's cursors and the unframed bytes; it is
self-contained and restores in the wasm32 kernel and back, byte-identical.
The framer's checkpoint fields moved into helpers shared with DWGO.

verify_r2007_objects.py and verify_wasm_r2007_objects.py check it against an
independent Python framing, the legacy reader and the AcDb:Handles map on
every pinned drawing and on built files, with fresh-process resumes in every
stage, forged checkpoints rejected and corrupt sections each ending in a named
error.
@DrunkOnJava
DrunkOnJava force-pushed the feat/stream-r2007-objects branch from 40e9a8a to 415fb98 Compare October 27, 2026 03:50
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 04:41
@DrunkOnJava
DrunkOnJava merged commit b5f0c5e into main Oct 27, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/stream-r2007-objects branch October 27, 2026 04:55
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