Skip to content

feat(streaming): stream the object records of an R2004-family file (#205) - #333

Merged
DrunkOnJava merged 10 commits into
mainfrom
stream3/objects
Oct 26, 2026
Merged

DrunkOnJava merged 10 commits into
mainfrom
stream3/objects

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Stream the object records of an R2004-family file out of the whole-file walker (#205): each record's MS, R2010 MC, payload, CRC, type and handle, with fixed state, byte-demand boundaries and a self-contained checkpoint that restores in wasm32. Along the way the R13 to R2000 walk's object map chunk limit was wrong and is fixed.

What changed

  • src/streaming/records.rs (new): ObjectFramer, the record framing; RecordFormat (R14, R2000 to R2007, R2010+). flat.rs now uses its prologue instead of a private copy.
  • src/streaming/r2004_objects.rs (new): R2004ObjectWalker, ObjectStep, ObjectDemand. The object section's data is framed in section order; every other section's data passes through. Records are emitted in stream order with the handle they carry; the AcDb:Handles map is not read and nothing is indexed.
  • R2004ObjectCheckpoint (DWGO, in checkpoint.rs), byte_source::poll_r2004_objects, examples/stream_r2004_objects.rs, size asserts in tools/streaming/no_std.rs.
  • Verifiers: verify_objects.py, verify_wasm_objects.py, wasm exports run_objects and resume_objects; both wired into the Streaming E2E job (timeout raised), with objects-corpus.json (the seven ACadSharp R2004-family drawings, cross-checked against pins.tsv).
  • R13 to R2000 half of goal 1: FlatWalker already emitted each record's payload provisionally and committed it at Step::Object (feat(streaming): walk the R13-R2000 container with byte-demand states #240), so those bodies were met. The change there is a bug found by running larger files (below) and two 1.3 MB drawings added to verify_walk.py (walk-acadsharp-corpus.json).
  • ARCHITECTURE.md §7ac, docs/streaming/README.md, CHANGELOG.md.

Findings (ARCHITECTURE.md §7ac)

  • On the 28 R2004-family drawings of the pinned corpus (8,007 records) the records tile the object section exactly after its 4-byte prologue, every record's CRC (seed 0xC0C1, MS through the last payload byte, MC included) verifies, and every MC is at most 8 times the payload. Three other CRC readings agree with none. The legacy walker never checked the CRC.
  • The object section's pages are in section order in the page map of all 28 drawings; AcDb:AcDsPrototype_1b is the only section of any drawing listed out of order. The walker refuses an out-of-order object page (ObjectsOrder) rather than keep an index; supporting it would need a bounded multi-pass walk and is not claimed.
  • Bug: FlatWalker refused an object map chunk over 2,032 bytes. A chunk's size counts its own two bytes, so AutoCAD's full chunk is 2,034 (2,033 and 2,034 in sample_AC1014.dwg and sample_AC1015.dwg). The walk failed on both with MapChunk; the evidence had stopped at 160 KB. Fixed; 1,242 and 1,047 records now equal the legacy reader's. The fix is one constant in src/streaming/flat.rs: the legacy reader (handle_map.rs, object.rs, reader.rs) is untouched, so no corpus count moves and the Corpus job's baseline is unchanged.

Test plan

No unit tests. Evidence is E2E, on real drawings, with repeatable artifacts (objects-evidence.json, wasm-objects-evidence.json, walk-evidence.json and the schedule logs):

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features, cargo test --release --all-features (existing suites, none adapted or added): pass.
  • python3 tools/streaming/check_invariants.py and the no_std.rs builds, native and wasm32: pass.
  • verify_objects.py (command in docs/streaming/README.md, 32 files = 4 fixtures + 28 pinned drawings, 8,027 records): output equal to the independent framing, the AcDb:Handles map and the legacy reader; 4 fixed and 128 proptest schedules; built files at page sizes from 4 bytes; 1,374 fresh-process resumes (every framer stage, 37 inside an MS, 18 inside an MC); 1,500 checkpoint bit flips and truncations and 158 resealed forgeries rejected; 49 corrupt object sections each ending in its named error.
  • verify_wasm_objects.py: 611 native checkpoints restored in the wasm32 kernel and the kernel's own in the native build, byte-identical in 611 of 611; 83 forgeries refused.
  • verify_walk.py with the two 1.3 MB drawings: 17 files pass; verify_wasm.py (the existing three walks, rebuilt kernel): 16 cases pass.
  • Run on the pinned corpus (tools/corpus/fetch.py --dest ~/Library/Caches/dwg-corpus) and its 19-file local subset (byte-identical to pinned files, ../../samples).

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. No Autodesk SDK, ODA Teigha/Drawings SDK or GPL DWG implementation source was consulted or imported. My contribution is based on the ODA's Open Design Specification for .dwg files (v5.4.1) and on measurements of the pinned public drawings; no algorithm-description comments from other projects were read.

)

R2004ObjectWalker is the whole-file walker with AcDb:AcDbObjects framed
into records in section order: each record's MS, R2010 MC, payload, CRC,
type and handle, with fixed state and a self-contained checkpoint. The
payload (the bytes the legacy RawObject::raw holds) is handed out as it
arrives and committed by an Object step after the CRC, type and handle
checks. Records come out in stream order with the handle they carry; the
AcDb:Handles map is not read and nothing is indexed. The walker refuses an
object page the page map lists out of order or a hole (ObjectsOrder)
rather than keep an index; every pinned drawing lists them in order.

Measured on the 28 pinned R2004-family drawings (8,007 records): the
records tile the section exactly after the 4-byte 0x0DCA prologue, every
record's CRC (seed 0xC0C1, MS through the last payload byte, MC included)
verifies, and every MC is at most 8 times the payload; three other CRC
readings agree with none (ARCHITECTURE.md 7v). The legacy walker never
checked the CRC.

Running the R13 to R2000 walk on two 1.3 MB drawings found that it refused
an object map chunk over 2,032 bytes. A chunk's size counts its own two
bytes, so AutoCAD's full chunk is 2,034 (2,033 and 2,034 in
sample_AC1014.dwg and sample_AC1015.dwg); the walk failed on both with
MapChunk. The limit is 2,034 now and both drawings are in verify_walk.py
(1,242 and 1,047 records equal to the legacy reader's).

R2004ObjectCheckpoint (DWGO, about 100 KB) holds the file walker's
checkpoint, the object section's id, the framer's cursors and the section
bytes not yet framed; restore requires a reachable state (the framer's CRC
is recomputed where its bytes are held, its MC re-read, the section checked
against the table and the unframed bytes against the section walker's
cursor). The wasm kernel gains run_objects and resume_objects.

verify_objects.py: every printed line equals an independent Python framing
of the independently assembled section, the AcDb:Handles map and the legacy
reader, on the four fixtures and the 28 drawings; fixed and proptest chunk
schedules; real object sections repacked at page sizes from 4 bytes and
with other sections' pages interleaved; fresh-process resume at 1,374 stops
including every framer stage and an MS and an MC split across pages; bit
flips, truncations and 118 resealed forgeries of checkpoints; 47 corrupt
object sections each ending in its named error with exactly the records
before it. verify_wasm_objects.py restores native checkpoints in the wasm32
kernel and the kernel's own in the native build, byte-identical in 611 of
611. Both run in the Streaming E2E job (timeout 30 minutes).
@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-26T18:40:41.818477Z 3845452 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: c653daccbf

ℹ️ 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/records.rs Resolved

@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: 738051036a

ℹ️ 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/records.rs Resolved
…etic and reject an MC of 2^64 (#205)

A forged but CRC-valid DWGO checkpoint could overflow u8 arithmetic in the
framer's reachable-state check (words 1 with a field length of 255) or reach
positions near u64::MAX, and an MC whose tenth byte held more than one payload
bit decoded to a small value because the shift dropped it. The check now
bounds every field before it computes with it, the stream length is bounded at
2^62 (more is CounterOverflow), the wrapper checks the framer first, and an MC
of 2^64 or more is RecordHeader, both when read and when re-read from a
checkpoint. verify_objects.py forges each case (158 resealed forgeries now)
and corrupts a real record's MC to 2^64 (49 corrupt sections).
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 18:45
@DrunkOnJava
DrunkOnJava merged commit eb6ead4 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the stream3/objects branch October 26, 2026 18:49
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