Skip to content

fix(rs-fec): implement §5.13's two Reed-Solomon codes as AutoCAD writes them (#275) - #286

Merged
DrunkOnJava merged 2 commits into
mainfrom
fix/275-reed-solomon-polynomial
Oct 26, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
fix/275-reed-solomon-polynomial

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

reed_solomon now implements §5.13's two R2007 Reed-Solomon codes the way AutoCAD writes them: system pages (255, 239) over 0x169, data pages (255, 251) over 0x11D, byte i the coefficient of x^i, roots α^1…, message first. Before, it decoded system pages over the data-page polynomial with the byte order reversed, and no codeword of a real file verified. Closes #275.

Spec reference

ODA spec v5.4.1 §5.13 (p65-66): the two configurations and their primitive-polynomial coefficients; §5.13.2 interleaving; §5.2 and §5.3 for where the system pages are. The root offset, byte order and message position are not in the spec; they are measured (ARCHITECTURE.md §7l).

Evidence

cargo run --release --example probe_r2007_rs -- <corpus dir> takes every codeword of every R2007 page (file header, page map, section map, and every data page of an encoding-4 section), de-interleaved per §5.13.2. For each it checks, through the crate's own decoder and encoder: intact (zero syndromes), re-encoded (encode_with on the message returns AutoCAD's codeword, parity included), corrected ((n-k)/2 injected errors restored), and, per page, verify_interleaved restoring one damaged byte per codeword. On the eight R2007 drawings of the pinned corpus:

Drawing System codewords (255,239) 0x169 Data codewords (255,251) 0x11D
ACadSharp sample_AC1021.dwg (AutoCAD 2025) 33 3,981
nextgis arc, circle, ellipse, line, point2d, point3d, polyline2d_line _2007.dwg (AutoCAD 2016) 22 each 61 to 73 each
All, every check passing 187 4,425

None verifies under the other code. Under the old module (0x11D, reversed order) none of the file header's three codewords verified (#275's measurement). A new Corpus-job step runs the probe on every pinned R2007 drawing and fails if none is reached.

API

  • Kept, now meaning the system-page code: reed_solomon::verify, syndromes, codewords_for_message, CODEWORD_BYTES, PARITY_BYTES, MESSAGE_BYTES, and reed_solomon_encode::encode (the fuzz target and tests/integration_fuzz_corpus_regression.rs use them unchanged).
  • Added: reed_solomon::Code (SYSTEM_PAGE, DATA_PAGE, verify returning the bytes corrected, verify_interleaved for §5.13.2, syndromes, codewords_for) and reed_solomon_encode::encode_with.
  • Removed: verify_stream and decode_stream, which read a block as back-to-back 255-byte codewords, a layout §5.13 never uses. Nothing called them. CHANGELOG records it.

The reader still takes message bytes without checking parity (r2007::deinterleave); wiring correction into it is not part of this change.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --release --all-features (the existing RS unit tests pass; one adapted to the new field type, none added)
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • cargo run --release --example probe_r2007_rs -- <corpus>: OK: every codeword of 8 R2007 file(s) checks out under §5.13
  • cargo run --release --example spec_examples: OK: 417 checks
  • Corpus ratchet unchanged (the reader does not call the module)

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. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported. This matters because dwg-rs is Apache-2.0 and must remain compatible.

My contribution is based on:

  • The ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1), §5.13;
  • The bytes of the pinned public corpus's R2007 drawings.

The Rockliff implementation §5.13 cites was not read; Berlekamp-Massey, Chien search and the systematic encoder are textbook algorithms written from scratch.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the
Developer Certificate of Origin 1.1.
Specifically, I affirm that the contribution is my own work (or rightfully
licensed to me) and that it can be distributed under the project's Apache-2.0
license.

…es them (#275)

System pages use (255,239) over 0x169 and data pages (255,251) over 0x11D, byte i the coefficient of x^i, roots alpha^1.., message first. examples/probe_r2007_rs.rs verifies, re-encodes and corrects every codeword of the pinned corpus's eight R2007 drawings; the Corpus job runs it.
@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-26T12:05:26.013691Z b4b9027 PR opened
ℹ️ 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 12:12
@DrunkOnJava
DrunkOnJava merged commit fdf145f into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/275-reed-solomon-polynomial branch October 26, 2026 12:13
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.

reed_solomon decodes R2007 system pages with the data-page polynomial (§5.13 gives 0x169, the crate uses 0x11D)

1 participant