Skip to content

fix(writer): emit the §4.1 header fields real R2004-family files carry - #259

Merged
DrunkOnJava merged 2 commits into
mainfrom
fix/writer-r2004-header
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
fix/writer-r2004-header

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

The writer now emits the §4.1 fixed file-header fields every real R2004-family file carries, and the four R2004-family canonical fixtures are regenerated. Closes #233.

Spec reference

ODA Open Design Specification for .dwg files v5.4.1, §4.1: plain 0x28 "0x00000080"; decrypted 0x0C "0x00", 0x10 "0x6c", 0x14 "0x04", 0x24 "Unknown long (ODA writes 1)", 0x44 "0x20", 0x48 "0x80", 0x4C "0x40"; and "The next 0x14 bytes will be copied from the magic number sequence, starting at 0x100 – 0x14".

assemble_dwg_bytes wrote a CRC-valid block with none of these. cipher::header_trailer runs the §4.1 generator on to 0x100 bytes for the trailing 0x14; the block CRC is still computed after every field is set.

Test plan

  • cargo run --release --example build_fixtures: deterministic (two runs, identical SHA-256), byte-identical to this commit. Only bytes 0x28–0xFF of each R2004-family fixture change (31 bytes each); synthetic_2000.dwg is untouched.
  • coverage_report tests/fixtures/canonical: 25 / 0 / 0, every handle-map entry resolved, no handle disagreeing with the map.
  • Independent Python §4.1 check: every field above now equals the value in all 21 pinned nextgis R2004/R2010/R2013 files and the local R2018 sample_AC1032.dwg; the CRC-32 still verifies.
  • cargo test --release --all-features with the 19-file real corpus: all suites pass, nothing prints "skipping"; fmt and clippy clean.
  • verify_lz77.py passes on the regenerated fixtures (page contents are unchanged; only header bytes moved).
  • The strict streaming R2004 header grammar (stacked branch feat/streaming-r2004-header) accepts the regenerated fixtures; it rejected the old ones.
  • No new unit tests.

Not in scope: the second header copy at the end of the file (address stays 0) and the LZ77 framing on #163.

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.

assemble_dwg_bytes wrote a CRC-valid encrypted file-header block but
none of §4.1's fixed fields. Every real R2004, R2010, R2013 and R2018
file checked carries the long 0x80 at plain 0x28; 0x6C, 4, 1, 0x20,
0x80 and 0x40 at decrypted 0x10, 0x14, 0x24, 0x44, 0x48 and 0x4C; and
in the 0x14 bytes after the block the magic sequence continued to 0x100
("copied from the magic number sequence, starting at 0x100 - 0x14").
The fixtures carried zeros. The writer now emits them, using
cipher::header_trailer for the trailing bytes; the CRC is computed after
them as before.

The four R2004-family fixtures are regenerated; only bytes 0x28-0xFF
of each change, and decoded entities and offsets are unchanged (25/0/0,
every handle-map entry resolved). The second header copy and the LZ77
stream framing (#163) remain as they were.

Closes #233
@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 🔄 Running since 2026-10-26T10:31:40.739599Z 7f4ed6e 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.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 10:31
@DrunkOnJava
DrunkOnJava merged commit 3df9c90 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/writer-r2004-header branch October 26, 2026 10:59
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.

Writer's R2004-family file header omits the §4.1 fixed fields real files carry

1 participant