Skip to content

Writer's R2004-family page checksums use another algorithm and the wrong header slots #265

Closed

Description

@DrunkOnJava

Found October 26, 2026 while measuring the R2004 system pages for the streaming R2004 walk (#205).

What real files carry (measured on line_2004, line_2013 and the R2018 sample_AC1032.dwg: both system pages and all 16, 13 and 54 data pages verify):

  • §4.3 system page (page map, section map): the checksum at 0x10 is the §4.2 section page checksum of the compressed data, seeded with the §4.2 checksum of the 0x14-byte header with that field zeroed.
  • §4.6 data page header (after the Sec_Mask): 0x10 start offset is a u64, 0x18 is the header checksum (§4.2 over the decoded header with this field zeroed, seeded with the data checksum), 0x1C is the data checksum (§4.2 over the page's compressed bytes, seed 0).

What the writer does:

  • file_writer::build_system_page writes 0 as the checksum.
  • section_writer::build_section writes a u32 start offset at 0x10, a "page checksum" at 0x14, a "data checksum" at 0x18 and 0x80 at 0x1C; both checksums use compute_checksum, a rotate-and-add sum that is not the §4.2 checksum, and the data checksum covers the decompressed bytes.

Every system page and every data page of the four canonical R2004-family fixtures therefore fails §4.2/§4.6. The legacy reader verifies none of these, so nothing fails today; a strict streaming page walk would reject the fixtures.

Related, not in this issue's fix: section_map::DataPageHeader labels its fields with the same shifted layout (start_offset as a u32 at 0x10, page_header_checksum at 0x14, data_checksum at 0x18, _unknown at 0x1C). The reader uses only page_type, data_size and the low half of the start offset, so no decode is affected.

Acceptance:

  • The writer emits the §4.3 and §4.6 checksums at the spec's offsets; the canonical fixtures are regenerated deterministically.
  • An independent check verifies every system and data page checksum of the regenerated fixtures, as it does on real files.
  • Decoded entities and offsets are unchanged on the canonical corpus.

Activity

  1. added
    type:bug
    area:container
    area:integrity
    area:writer
    release:R2004
    release:R2010
    release:R2013
    release:R2018
    priority:P2
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 26, 2026
    86dc347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:containerarea:integrityarea:writerpriority:P2release:R2004release:R2010release:R2013release:R2018type:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions