Skip to content

feat(streaming): verify the R2004-family file header with byte-demand states - #260

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

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

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

streaming::R2004HeaderParser verifies the R2004-family file header (AC1018, AC1024, AC1027, AC1032) with the same byte-demand, checkpoint and no-allocation contract as the flat header. It is the entry of the R2004+ container walk (#205); the page-map and section walk is not in this PR.

Spec reference

ODA Open Design Specification for .dwg files v5.4.1, §4.1, with §4.3's 0x20 page boundary for the page-map address. Enforced: plain 0x28 = 0x80; decrypted file ID, CRC-32 (CRC field zeroed, "the CRC calculation takes into account all of the 0x6c bytes"), fixed fields at 0x0C, 0x10, 0x14, 0x44, 0x48, 0x4C; the 0x14 trailing magic bytes; a page map on a 0x20 boundary with its header inside the source; a non-zero second-header address inside the source. A failing field is R2004Field(file offset), a CRC mismatch R2004HeaderCrc. Plain bytes the spec calls zero but real files fill (0x15–0x17, 0x2C–0x7F) and the "unknown" decrypted 0x24 are not enforced. State is bounded at 512 bytes and the DWG4 checkpoint at 336 (at most 316 on the wire), both in the no_std kernel, native and wasm32-unknown-unknown.

Rests on #259 (the writer fix that makes the canonical fixtures carry the §4.1 fixed fields) and #255, both on main.

Test plan

  • python3 tools/streaming/verify_r2004.py target/debug/examples/stream_r2004 target/debug/examples/streaming_schedules: the four canonical R2004-family fixtures and the 21 pinned nextgis R2004/R2010/R2013 files. Every header equals an independent Python §4.1 parse and the legacy header::R2004Header fields; chunk sizes 1–32 and a mixed schedule with Pending polls reproduce it; 128 proptest schedules on each of three files; a cut at each of the 256 header bytes is Truncated. On the canonical R2004 fixture and one real file per release band, twelve corruptions (three magics, 0x28, file ID, CRC, two fixed fields, trailer, page map past the end and off its boundary, second header past the end) each end in their named error with nothing printed. Fresh-process resume at all 257 positions reads each byte exactly once. Bit flips at every byte (160), every truncation and a wrong identity are rejected for a mid-header checkpoint; a failure snapshot restores its failure.
  • By hand: the local R2018 sample_AC1032.dwg (Establish the provenance of sample_AC1032.dwg, the one R2018 file #96) parses and matches the legacy fields.
  • fmt, clippy, cargo doc -D warnings, kernel builds, check_invariants.py, build_fixtures byte-identical.
  • No new unit tests.

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.

… states

R2004HeaderParser reads the first 0x100 bytes of an AC1018, AC1024,
AC1027 or AC1032 file under the flat header's contract: exact demands,
partial feeds kept, invalid delivery rejected without mutation, terminal
errors, and no output until every §4.1 check passes. It enforces the
long 0x80 at 0x28; the decrypted block's file ID, CRC-32 and fixed
fields at 0x0C, 0x10, 0x14, 0x44, 0x48 and 0x4C; the 0x14 trailing magic
bytes; a page map on a 0x20 boundary inside the source; and a non-zero
second-header address inside the source. Failures name the field's file
offset (R2004Field) or the CRC (R2004HeaderCrc). It compiles in the
no_std, no-allocator kernel natively and for wasm32, bounded at 512
bytes; R2004Checkpoint (DWG4, at most 316 bytes, bounded at 336) is
restored by replay.

stream_r2004 is the entry point; --legacy prints the legacy header's
fields under the same keys. verify_r2004.py runs it on the four
canonical R2004-family fixtures and the 21 pinned nextgis R2004, R2010
and R2013 files: every header equals an independent Python parse and the
legacy reader, under 33 chunk schedules and 128 proptest schedules on
three files, and a cut at each of the 256 header bytes is Truncated.
Twelve corruptions per release band end in their named error with
nothing printed; fresh-process resume at all 257 positions reads each
byte once; corrupt, truncated and wrong-identity checkpoints are
rejected and a failure snapshot restores its failure. It runs in the
required Streaming E2E job.

Refs #205
@DrunkOnJava
DrunkOnJava force-pushed the feat/streaming-r2004-header branch from afeb314 to 940a337 Compare October 26, 2026 11:26
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review October 26, 2026 11:26
@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-26T11:28:19.315711Z 940a337 Draft marked ready
ℹ️ 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 11:39
@DrunkOnJava
DrunkOnJava merged commit 069cb35 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/streaming-r2004-header branch October 26, 2026 11:47
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