Skip to content

fix(writer): emit the §4.3 and §4.6 page checksums real files carry - #266

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/writer-page-checksums
Oct 26, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
fix/writer-page-checksums

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

The writer now emits the §4.3 system-page and §4.6 data-page checksums real R2004-family files carry, at the spec's offsets, and the four R2004-family canonical fixtures are regenerated. Closes #265.

Spec reference

ODA Open Design Specification for .dwg files v5.4.1:

  • §4.2 section page checksum (the Adler-style sum with a 0x15B0 chunk), crc::section_page_checksum.
  • §4.3: "First the checksum ... is calculated from the header data, using a seed of 0. The header data's checksum being 0 at this stage ... In the second stage the final checksum is calculated from the compressed data, using the first checksum as the seed."
  • §4.6: 0x10 start offset (OdUInt64), 0x18 "Page header Checksum (section page checksum calculated from the decoded header bytes, with this field itself zeroed, using the data checksum as seed)", 0x1C "Data Checksum (section page checksum calculated from compressed data bytes, with seed 0)".

file_writer::build_system_page wrote 0. section_writer::build_section wrote a u32 start offset, two rotate-and-add sums (one over the decompressed bytes) at 0x14 and 0x18, and 0x80 at 0x1C. compute_checksum stays (benchmarked, public) with its doc corrected.

Test plan

  • Independent §4.2 check (Python, written from the spec) on real files first: both system pages and all data pages of line_2004 (16), line_2013 (13) and sample_AC1032 (54) verify; on the old fixtures every one failed; on the regenerated fixtures every system page and all 3 data pages of each fixture verify.
  • cargo run --release --example build_fixtures: deterministic (two runs, identical SHA-256).
  • coverage_report tests/fixtures/canonical: 25 / 0 / 0, every handle-map entry resolved.
  • verify_lz77.py on the regenerated fixtures; cargo test --release --all-features with the 19-file corpus (all suites pass, nothing skipped); fmt; clippy -D warnings.
  • No new unit tests. Reader code is untouched, so the Corpus baseline cannot move.

Related and recorded on #265, not changed here: section_map::DataPageHeader labels its fields with the same shifted layout; the reader reads only fields that sit where it expects.

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.

Base automatically changed from fix/writer-r2004-header to main October 26, 2026 10:59
Every real R2004-family file checked (both system pages and all 16, 13
and 54 data pages of line_2004, line_2013 and sample_AC1032) carries
the §4.2 section page checksum: on a system page, over the compressed
data seeded with the checksum of the 0x14-byte header with the field
zeroed (§4.3); on a data page, a data checksum over the compressed bytes
at 0x1C and a header checksum at 0x18 over the decoded header with that
field zeroed, seeded with the data checksum, after a u64 start offset
at 0x10 (§4.6).

build_system_page wrote 0. build_section wrote a u32 start offset, two
rotate-and-add sums (one over the decompressed bytes) at 0x14 and 0x18,
and 0x80 at 0x1C. Both now write the spec's checksums at the spec's
offsets; compute_checksum's doc no longer claims to be the §4.2 sum.

The four R2004-family fixtures are regenerated deterministically; every
system and data page checksum in them now verifies under an independent
§4.2 implementation, and decoded entities and offsets are unchanged
(25/0/0, every handle-map entry resolved).

Closes #265
@DrunkOnJava
DrunkOnJava force-pushed the fix/writer-page-checksums branch from 4d4f4bd to 86dc347 Compare October 26, 2026 11:02
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review October 26, 2026 11:02
@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:03:45.180933Z 86dc347 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 merged commit 209e96c into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/writer-page-checksums branch October 26, 2026 11:21
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 page checksums use another algorithm and the wrong header slots

1 participant