Repository navigation
fix(rs-fec): implement §5.13's two Reed-Solomon codes as AutoCAD writes them (#275) - #286
Merged
Merged
Conversation
…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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
reed_solomonnow implements §5.13's two R2007 Reed-Solomon codes the way AutoCAD writes them: system pages (255, 239) over0x169, data pages (255, 251) over0x11D, 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_withon the message returns AutoCAD's codeword, parity included), corrected ((n-k)/2 injected errors restored), and, per page,verify_interleavedrestoring one damaged byte per codeword. On the eight R2007 drawings of the pinned corpus:0x1690x11Dsample_AC1021.dwg(AutoCAD 2025)arc,circle,ellipse,line,point2d,point3d,polyline2d_line_2007.dwg(AutoCAD 2016)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
reed_solomon::verify,syndromes,codewords_for_message,CODEWORD_BYTES,PARITY_BYTES,MESSAGE_BYTES, andreed_solomon_encode::encode(the fuzz target andtests/integration_fuzz_corpus_regression.rsuse them unchanged).reed_solomon::Code(SYSTEM_PAGE,DATA_PAGE,verifyreturning the bytes corrected,verify_interleavedfor §5.13.2,syndromes,codewords_for) andreed_solomon_encode::encode_with.verify_streamanddecode_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 -- --checkcargo clippy --all-targets --all-features -- -D warningscargo 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-featurescargo run --release --example probe_r2007_rs -- <corpus>:OK: every codeword of 8 R2007 file(s) checks out under §5.13cargo run --release --example spec_examples:OK: 417 checksSource-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:
CLEANROOM.md).dwg-rsis Apache-2.0 and must remain compatible.My contribution is based on:
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.