Repository navigation
fix(object-types): R2004 object prologue — read the R2000-R2007 RL obj_size and the non-entity common object data - #27
Merged
Conversation
…y common object data ODA v5.4.1 §19.1 puts an `RL` "object data size in bits" between the object type and the object handle for the whole R2000..R2007 band; R2010+ replaces it with the leading `MC` handle-stream size. The reader consumed it for R2000 alone, leaving every AC1018 record 32 bits out of phase from the handle onwards — ~20 `Bit cursor exhausted` errors per R2004 sample. Also read the §19.4.2 common object data (EED chain, `BL` reactor count, xdictionary flag) before the pre-R2007 symbol-table decoders, which started at the entry name with the cursor still on the EED chain; fix the legacy STYLE decoder's `RC`-for-two-`B`-bits overread; and give the legacy VPORT decoder the same field table as the already-verified R2007+ split-stream decoder. samples/ corpus: R2004 15 decoded / 60 errored / 2.5% -> 75 / 0 / 12.6%; aggregate 527 / 94 / 23.1% -> 587 / 34 / 25.7%. All remaining errors are in the single R2018 sample. Closes #24
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_6db688a4-8b88-44a5-87bf-4363328d8e55) |
7 tasks done
This was referenced Aug 30, 2026
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
The R2004 (AC1018) object prologue was missing a field. ODA v5.4.1 §19.1 puts an
RLobject data size in bits between the object type and the object handle for the whole R2000..R2007 band — R2010+ replaces it with the leadingMChandle-stream size. The reader consumed it forVersion::R2000only, so every AC1018 record was 32 bits out of phase from the handle onwards. That is the whole ofBit cursor exhausted: wanted 8 bits, N bits remainon the three R2004 samples.Fixing the prologue exposed three further pre-R2007 bugs in the same code path, all fixed here.
Spec reference
§19.1 — object record prologue.
Read through the new
Version::has_object_size_field()predicate in bothobject::ObjectWalker::read_one_at_posandentities::dispatch::position_cursor_at_entity_body, and surfaced asRawObject::obj_size_bits— the bit at which an object's data stream ends and its handle stream begins, i.e. the pre-R2010 analogue of the R2007+ string-stream start bit, and therefore the invariant a decoder can validate itself against.Evidence from
examples/dump_line_payload.rs(extended to be version-aware) online_2004.dwg:obj_sizeRL0x18395D087600000(nonsense)RL= 3470x83(50,50,0) -> (100,100,0)The recovered geometry matches what
line_2013.dwgalready asserts, and the record lands on its ownobj_sizewith zero deviation.§19.4.2 — common object data. Non-entity objects (symbol-table entries, dictionaries) carry a shorter prefix than the §19.4.1 entity preamble — no graphics block, no entity mode, but the same EED chain,
BLreactor count and xdictionary-missing flag. The pre-R2007 table decoders were starting at the entry name with the cursor still parked on the EED chain.common_entity::read_common_object_datanow consumes it.examples/probe_r2004_object_prefix.rs(new) prints every candidate prefix side by side for a given type code. Online_2004.dwgonlyEED + BL + Byields readable names:""""""""EED""""""""EED + B<truncated><TV len 66><TV len 65><TV len 66>EED + BL""""""""EED + BL + B0StandardACADByBlock(plus
Annotative,AcadAnnotative,ACAD_NAV_VCDISPLAY,ACAD_EXEMPT_FROM_CAD_STANDARDS,ByLayer,Continuous,*Model_Space,*Paper_Spaceon the rest of the records.)§20.4.56 — STYLE. The legacy inline decoder read an
RCwhere the field table has twoBbits (shape file, vertical), overrunning each record by exactly the 6 extra bits. The R2007+ split-stream decoder already had this right.§20.4.8 — VPORT. The legacy inline decoder followed an abbreviated field list (
2 × BDview centre instead of2RD,BSview mode instead of4BITS, and no UCS / grid tail at all). It now reads the same field table as the already-verified R2007+ split-stream decoder, minus the R2007+ lighting/ambient-colour block and the two trailing gridBSwords. That is the only list which consumes the*Activerecord's 1127 body bits exactly (obj_size = 1240, common object data ends at bit 113), and it yields sane values: height 288.07, width 585.69 with centre x = 292.84 = 585.69/2 — the same "secondBDis the view width, not an aspect ratio" relation the R2013 record was measured against.Measured coverage — before / after
cargo run --release --example coverage_report -- <samples>over the 19-file corpus:Per-file, each R2004 sample goes from
5 / 174 / 20 / 2.5 %to25 / 174 / 0 / 12.6 %. All 34 remaining errors in the corpus are now in the single R2018 file; every R2004, R2010 and R2013 sample decodes with zero errors.Table entries on
line_2004.dwgalso stop returning silent garbage:Canonical-corpus fixture change
tests/canonical_corpus.rspins decoded field values on the synthetic fixtures.examples/build_fixtures.rswas writing the AC1018 record without theRL, i.e. encoding the same bug the reader had, so the fixture and the reader agreed on a wrong layout. The generator now emits the field for the R2000..R2007 band (two-pass: the field is fixed width but its value depends on the body length, so the payload is built once with a placeholder to measure and once with the measured value).Consequence:
tests/fixtures/canonical/synthetic_2004.dwgchanged.synthetic_2010/2013/2018.dwgare byte-identical, and none of the value pins intests/canonical_corpus.rsmoved — the fixture still decodes to the same five entities with the same coordinates.Test plan
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --release— 666 lib tests + all integration suites pass (was 664; +2 new)cargo deny check allRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-featurescargo +1.85.0 test --no-run(MSRV, no let-chains)New tests:
entities::dispatch::tests::r2004_line_record_decodes_and_ends_on_obj_size— builds a complete R2004 object record withBitWriter(OT,RL,H, §19.4.1 preamble, §19.4.20 LINE body), walks it through the publicdecode_from_raw, asserts the geometry, and asserts the negative case: skipping theRLmust not produce a valid LINE.entities::dispatch::tests::r2004_common_object_data_consumes_reactor_count—BitWriter-built §19.4.2 prefix followed by aTV, asserting the reactor count and that the name lands correctly.tables::style::testsandtables::vport::testslegacy round-trips were updated to the corrected field tables.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:
This contribution is based on the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1) and on first-party byte inspection of publicly-available sample DWG files, reproduced by the two probes under
examples/. No permissively-licensed third-party comments were consulted, so noCLEANROOM.mddisclosure entry is needed.Closes #24
Note
Medium Risk
Changes bit alignment for every R2000–R2007 object record and alters table-entry decode entry points; mistakes would corrupt handles and geometry, but the change is spec-scoped and backed by corpus and unit tests.
Overview
Fixes R2004 (AC1018) object-record alignment by reading the §19.1
RLobject data size in bits for the whole R2000..R2007 band (not only R2000), gated byVersion::has_object_size_field()in the object walker and entity cursor positioning. The value is exposed asRawObject::obj_size_bitsso decoders can verify where the data stream ends.Pre-R2007 symbol-table dispatch now consumes §19.4.2 common object data (
EED+ reactor count + xdictionary flag) before inline table decoders; legacySTYLEandVPORTfield layouts are corrected to match measured R2004 bytes.Corpus impact: all three R2004 samples go from 60 errors to zero; aggregate decode success rises from 23.1% to 25.7%. Synthetic
synthetic_2004.dwgis regenerated with a two-passRLemit inbuild_fixtures, plus new probe examples and dispatch unit tests.Reviewed by Cursor Bugbot for commit b4a3d1e. Configure here.