Repository navigation
feat(objects): dispatch the non-entity objects and read their TV fields from the R2007+ string stream - #36
Merged
Conversation
…ds from the R2007+ string stream Non-entity objects were unreachable from `decode_from_raw` — every DICTIONARY, XRECORD, `*_CONTROL` and ACDB_PLACEHOLDER in the corpus was short-circuited to `Unhandled` — and the ones that were reachable directly read their `TV` fields inline, so they were silently wrong on R2007+. - New `src/objects/modern.rs`: one field list per decoder serves both layouts, and `ObjectStream::finish` asserts the data fields end exactly on the record's data-stream boundary. - `entities::dispatch::dispatch_object` routes DICTIONARY, XRECORD, ACDB_PLACEHOLDER, ACAD_GROUP and the ten `*_CONTROL` owners; `dispatch_object_class` routes SCALE, DICTIONARYVAR, ACDBDICTIONARYWDFLT and IMAGEDEF by DXF class name. - Measured corrections: the common object data keeps its `BL num_reactors` on R2007+; DICTIONARY's names are a block, not name/handle pairs; ACAD_SCALE is `BS, TV, BD, BD, B`; ACAD_GROUP is `TV, BS, BS, BL`; DIMSTYLE_CONTROL carries one extra `RC`. - `ClassMap::parse` read the class list from the wrong offset and returned an empty table on every real file; fixed, with the R2007+ split-record layout, and `write_class_map` rewritten as its inverse. - LIGHT's version-blind private `read_tv` removed; LIGHT, GEODATA and IMAGEDEF now read through the split stream (#32). Coverage on the 19-file corpus: 597 / 1660 / 24 / 26.2% before, 1706 / 549 / 26 / 74.8% after. Closes #33 Closes #32
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_4109857f-751e-4cf2-a53e-84e887a33418) |
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
Two things were wrong with the non-entity objects, and they compounded:
decode_from_rawshort-circuited every object that is neither a drawing entity nor a symbol-table entry straight toUnhandled, so the 65 DICTIONARY records ofsample_AC1032.dwg— and every XRECORD,*_CONTROLand ACDB_PLACEHOLDER in the corpus — counted as "skipped" no matter how good the decoder behind them was.TVfields inline, so on R2007+ they returned whatever bits sat at that offset and never errored.Fixing (1) without (2) would have manufactured a coverage number out of garbage, so this PR does both, plus the third thing that turned out to be blocking every
Custom(N)object:AcDb:Classeswas being read from the wrong offset and returned an empty table on every real file.Every decoder reached from the new dispatch path is self-validating:
objects::modern::ObjectStream::finishrequires the data fields to end exactly on the record's data-stream boundary, so a wrong field list producesDecodedEntity::Error, never a plausible-looking struct that inflates the ratio.What landed
src/objects/modern.rs(new) — the object analogue oftables/modern.rs. One field list per decoder serves both layouts (read_tvtakes from the string stream on R2007+, inline before that), andfinishenforces the boundary:B"strings present" trailer bitRLobject-data-size-in-bits from the object prologueDispatch —
dispatch_objectroutes DICTIONARY, XRECORD, ACDB_PLACEHOLDER, ACAD_GROUP and the ten*_CONTROLowners;dispatch_object_classroutes SCALE, DICTIONARYVAR, ACDBDICTIONARYWDFLT and IMAGEDEF by DXF class name.DispatchSummarysemantics are unchanged — a new kind counts as decoded only when its decoder returnsOk, and a class whoseitem_class_idis0x1F3with no object decoder returnsUnhandledrather than being fed to the entity preamble reader.New decoders —
objects::placeholder(ACDB_PLACEHOLDER),objects::dictionary_var(DICTIONARYVAR).Issue LIGHT, GEODATA, IMAGEDEF read TV fields inline on R2007+; LIGHT's private read_tv ignores the version entirely (always 8-bit) #32 — LIGHT's private
read_tvignored itsversionargument and always read 8-bit inline; LIGHT exists only from R2007, the release that movedTVinto the string stream, so it was doubly wrong. LIGHT, GEODATA (fiveTVs, one a full WKT/PROJ string) and IMAGEDEF now read through the split stream, each self-validating.examples/probe_object_layout.rs(new) — the instrument behind every "measured" claim below. It prints, per record, the bit budget from the end of the common object data to the data-stream boundary under both candidate prefixes, the raw bits, and the strings the string stream holds.examples/coverage_report.rsnow also prints an unhandled histogram by object kind, so the next-largest lever is visible from the report.Measured coverage
cargo run --release --example coverage_report -- /Users/griffin/Developer/re/dwg-recon-2026-04-19/samples(19 files, read-only archive):The two extra errors on the R2018 sample are the second STYLE_CONTROL and the second DIMSTYLE_CONTROL record, whose bytes are not a control object at all (they were previously counted as "skipped" without anything having tried to read them). Every other file still decodes with zero errors.
Verification on
sample_AC1032.dwgcargo run --release --example dump_decoded_entities -- .../sample_AC1032.dwg:and on
arc_2013.dwg, where the class map now resolves:Real strings, and the SCALE ratios are semantically right (
1:2→ paper 1 / drawing 2, and only1:1is flagged as the unit scale).LAYOUT is not in that list on purpose. Its names are real strings in the string stream (
audit_string_streamsshows"Layout1","Model","ANSI_A_(8.50_x_11.00_Inches)"), but LAYOUT embeds the whole PLOTSETTINGS field list ahead of them and this crate has not matched that list against real bytes yet, so it cannot satisfy the boundary check. Rather than guess, it staysUnhandledand the offsets are documented — see the follow-ups below.Measurements
Every layout change below is read off bytes in the read-only sample archive, not inferred from the spec alone.
The common object data (§19.4.2) keeps its
BL num_reactorson R2007+. Three independent confirmations:BL numitemsdecodes to the number of strings its string stream actually holds only with theBLconsumed — 23 for the named-object dictionary, 4 for the layout dictionary, 2 for the group dictionary, 0 for the empty ones. Without it,numitemsreads 0 on a dictionary that demonstrably has entries.arc_2013.dwg—BS 0(2) +BL 1(10) +B+B+ the one-bit §19.1 trailer. Without theBL, 2 bits are left over.*_CONTROLrecords close on theirBL numentriesonly with the reactor count consumed first.DICTIONARY's entry names are a block, not name/handle pairs.
arc_2004.dwghandle 16 (the linetype dictionary): itsRLobject-data-size ends 255 bits past the header, andBL numitems = 3,BS cloning = 1,RC hard-owner = 0plus threeTVs consumes exactly those bits, the first reading length 8 followed by the ASCII bytes ofByBlockand its NUL. Reading a handle after each name desynchronises on the second entry.Dictionary::entries: Vec<DictionaryEntry>therefore becameDictionary::keys: Vec<String>, whose index is the index of the matching item handle.ACAD_SCALE is
BS version, TV name, BD paper, BD drawing, B is_unit_scale— notTV, BD, BD, BS.arc_2004.dwg's1:1record spends its 49-bit budget exactly asBS 0/TVof length 4 whose bytes are31 3A 31 00/BD 1.0/BD 1.0/B 1.arc_2013.dwg's1:2record spends 71 bits asBS 0/BD 1.0/ a full 66-bit double whose LE bytes are00 00 00 00 00 00 00 40(2.0) /B 0.ACAD_GROUP is
TV, BS, BS, BL— not twoBflags. Both GROUP records ofsample_AC1032.dwgleave exactly 30 bits for three 10-bit fields reading 2, 1 and 6; the boolean reading ran the trailingBLoff the end, which is why both failed to decode. The first field reading 2 rather than 0/1 is why it is surfaced as a rawi16: the width is established, that value's semantics are not, and there is no second file with a GROUP record to cross-check.DIMSTYLE_CONTROL carries one extra
RC— 8 bits pastnum_entriesonarc_2004.dwg(value 1),arc_2013.dwg(1) andsample_AC1032.dwg(4), while the other nine controls close with nothing left over. Surfaced verbatim asControl::dimstyle_trailing_rcrather than named after a guess.AcDb:Classesstarts at byte 20 on R2004 and byte 28 on R2010+. The old parser started at byte 24 for every release and readmax_class_numberas a byte-alignedRLfrom bytes 20-24; it read class number 0 and desynchronised immediately, so the table was empty on every real file and noCustom(N)object could be dispatched at all.arc_2004.dwg86 02 00 00then3F 40 40 00 …00+1111110100000001BS= 509arc_2010.dwg42 04 00 00 00 00 00 00 0A 22 00 00then3F 40 40 00 …BS= 509arc_2013.dwgD9 03 00 00 00 00 00 00 C3 1E 00 00then3F 00 40 00 …00+1111110000000001BS= 508sample_AC1032.dwg66 18 00 00 00 00 00 00 2A C3 00 00then09 40 80 00 …00+0010010100000010BS= 549From R2007 the records themselves split the same way object records do — all the non-string fields first, then
3 × Nstrings as a block. Onarc_2013.dwgthat yields nine records numbered 500..=508, item class id0x1F3throughout, object counts 1/3/24/17/1/1/1/1/5 matching the object stream exactly, and 27 strings reading"ObjectDBX Classes","AcDbDictionaryWithDefault","ACDBDICTIONARYWDFLT","ObjectDBX Classes","AcDbMaterial","MATERIAL", … in order.ClassMap::parseaccepts a table only when the class numbers run consecutively from 500, so a mislocated stream reports no classes rather than a desynchronised list.write_class_mapwas rewritten as the true inverse and round-trips in both layouts.Spec sections
ODA Open Design Specification for .dwg files v5.4.1: §19.1 (object data / R2007 split-stream layout and its trailer), §19.4.2 (common object data), §19.5.1-§19.5.10 (
*_CONTROL), §19.5.19 (DICTIONARY), §19.5.26 (IMAGEDEF), §19.6.5 (XRECORD), §19.6.7 (ACAD_GROUP), §19.6.8 (ACAD_SCALE), §19.4.94 (LIGHT), §19.4.95 (GEODATA), §5.7 / §21.4.2 (AcDb:Classes), §5 Table 4 (object type codes), §2 (bit-code primitives).Not determined — documented and stopped
Per the project's rule against guessing a layout that the bytes do not settle:
TVs per LAYOUT record, budgets of 808 / 400 / 424 bits onarc_2013.dwg; the numeric field list between them is not established. LeftUnhandled.arc_2013.dwghandle 96 — the firstBDdecodes to ~1e-226 rather than an angle. LeftUnhandled.AcDb:Classesrecord layout.sample_AC1032.dwgdeclares 50 classes but its ninth record does not decode with the field list that works on R2004/R2010/R2013, so the consecutiveness check rejects the table and all 194Custom(N)records in that file — including its 33 SCALE records — stayUnhandled.tables/modern.rsomits theBL num_reactorsthis PR measured as present on every non-entity object, and compensates with a different flag order, so both readings land on the string stream and both satisfy the boundary check. Which one assigns the right values to the right fields is not determinable from the 16 bits an APPID record spends there. Names are unaffected (they come from the string stream either way), so this PR does not touch the table path.Gate
tests/canonical_corpus.rspins are unchanged — none of them touch the object structs.Test-shape changes, each because the behaviour they pinned is the behaviour this PR fixes:
tests/code_table_agreement.rs—non_entity_codes_route_to_unhandledsplit intonon_entity_codes_with_decoders_are_routed_not_unhandled(DICTIONARY, XRECORD, ACDB_PLACEHOLDER, GROUP, four controls) andnon_entity_codes_without_decoders_stay_unhandled(MLINESTYLE, LAYOUT, LONG_TRANSACTION).tests/dispatch_roundtrip.rs— the same split, plus a property test that the object decoders are total on random bytes.src/classes.rs— the writer round-trip tests now assert the measured header shape and cover both record layouts.Source-provenance declaration
Clean-room declaration. I certify that:
CLEANROOM.md— the public ODA Open Design Specification for .dwg files v5.4.1, the public AutoCAD DXF group-code reference, and first-party byte inspection of the publicly-available sample DWGs in the local read-only recon archive (nextgis/dwg_sampleslineage). In particular I did not consult Autodesk SDK source, ODA SDK (Drawings SDK / Teigha) source, LibreDWG source, decompilations of Autodesk or ODA binaries, or any copyleft-licensed DWG implementation code.examples/probe_object_layout.rsreproduces every one of them.Closes #33
Closes #32
Note
Medium Risk
Large bit-level decoder and dispatcher changes affect how untrusted DWG bytes are interpreted; boundary checks and tests mitigate silent mis-decode but R2018 class-table and undispatched types remain gaps.
Overview
Non-entity objects (DICTIONARY, XRECORD,
*_CONTROL, GROUP, placeholders, custom SCALE/DICTIONARYVAR/IMAGEDEF) are now routed through dedicated decoders instead of always returningUnhandled, which is why corpus decode coverage jumps from ~26% to ~75% on the measured samples.The PR adds
objects::modern(parallel totables::modern): one field list per object type,TVfrom the R2007+ string stream when applicable, andObjectStream::finishso data fields must end exactly on the record boundary—wrong layouts becomeDecodedEntity::Error, not plausible garbage.Wire-format fixes include DICTIONARY keys as a name block (handles live after the data stream), corrected ACAD_SCALE / ACAD_GROUP field lists, DIMSTYLE_CONTROL’s extra trailing
RC, and LIGHT, GEODATA, and IMAGEDEF readingTVfrom the split stream.ClassMap::parsewas reading the class list from the wrong byte offset and treatingmax_class_numberas anRL; it now matches R2004 vs R2010+ headers, R2007+ split class records, and a consecutiveness check—unlockingCustom(N)dispatch on older files (R2018 still blocked when the ninth class record does not decode).Tooling/docs: new
probe_object_layout, coverage_report unhandled histogram,object::body_cursor/data_end_bit, and updated architecture/changelog/status coverage tables.Reviewed by Cursor Bugbot for commit 4f07e61. Configure here.