Repository navigation
fix(class-map): the class record's version fields are BL, not BS (closes #37) - #41
Merged
Merged
Conversation
The ODA v5.4.1 spec states the AcDb:Classes record twice and the two statements disagree. Section 10.2 (R18+) gives `BS max_class_number` + two `RC 0x00`, `BS dwg_version` and `BS maintenance_version`; section 5.8 (R2007) gives `BL` for all three. The bytes side with 5.8. The two readings are bit-identical on the `10` (zero) and `01` (one-byte) tags and differ only on tag `00`, where BS takes an 18-bit RS and BL a 34-bit RL — so the 10.2 reading survives every file whose classes keep both version fields under 256. sample_AC1032.dwg is the first that does not: MLEADERSTYLE (508), ACDBDETAILVIEWSTYLE (516), WIPEOUT (520) and MULTILEADER (526) record dwg_version 33 and maintenance_version 329, making those records 113 bits wide where every other record on the file is 57-89. Reading 329 as a BS lost 16 bits at record 8, record 9 hit the reserved `11` BL tag, the consecutiveness check discarded the table, and all 194 Custom(N) objects on the file fell through to Unhandled. Corroborated three ways: exactly max_class_number - 500 + 1 records decode with consecutive class numbers on arc_2010 / arc_2013 / sample_AC1032; the 3 x N strings that follow end precisely at the section's string-stream trailer (length words 7788 / 7038 / 45804 bits, each equal to the measured span); and the num_objects field now carried on ClassDef matches the object walk exactly on the high-count classes (VISUALSTYLE 240/240, SCALE 186/186, MLEADERSTYLE 11/11). ClassDef gained num_objects, dwg_version and maintenance_version, and write_class_map round-trips them instead of writing zeros, so the writer stays the exact inverse including the oversized-BL case. examples/probe_class_layout.rs is the reproducer; coverage_report.rs now names custom classes in its unhandled histogram. Measured on the 19-file local corpus: R2004 x 3 489 / 108 / 0 / 81.9% (unchanged) R2010 x 3 438 / 105 / 0 / 80.7% (unchanged) R2013 x 3 291 / 105 / 0 / 73.5% (unchanged) R2018 x 1 488 / 231 / 26 / 65.5% -> 533 / 166 / 46 / 71.5% Aggregate 1706 / 549 / 26 / 74.8% -> 1751 / 484 / 46 / 76.8% 65 R2018 records left skipped: 45 now decode (its 33 SCALE among them) and 20 now reach a decoder and fail in the R2007+ common entity preamble tracked under #103. Those 20 were always broken; the missing class table was hiding them. Closes #37 Claude-Session: https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
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_a3bd1aa9-4829-4b0f-8a28-59d54c1b8a3c) |
This was referenced Aug 30, 2026
DrunkOnJava
added a commit
that referenced
this pull request
Aug 30, 2026
… BLL (#46) The common entity preamble (§19.4.1) opens with the EED chain and a `B` "graphics present" flag; when set, a size field and that many bytes of proxy graphics follow. That size field is an `RL` up to R2007 and a `BLL` (§2.4) from R2010 on. Reading it as an `RL` on R2018 produced preview sizes in the millions of bytes for records a few hundred bytes long and ran the byte-skip loop off the end of the record inside the preamble — the 20 errors #41 newly surfaced on sample_AC1032.dwg. The failures looked class-shaped because AutoCAD writes proxy graphics for entities whose class it does not implement natively, so the flag is set on exactly MULTILEADER / MESH / ACAD_TABLE / WIPEOUT / IMAGE and clear on LINE / TEXT / MTEXT. The field list is identical either way. `3B` is three raw bits, not a stop-at-zero prefix code: the old reading could only produce {0, 2, 6, 7}, and the file requires a one-byte length. IMAGE 0x662 and WIPEOUT 0x44D write `001` + 0x8C = 140 bytes, MULTILEADER 0x66E writes `010` + 0x50 0x03 = 848, MESH 0x343 writes 9512 — and each lands the rest of the preamble on the same field values every plain entity in the file carries (entmode 2, 0 reactors, colour 0x0100, linetype scale 1.0, invisibility 0, lineweight 0x1D). Three body fixes fall out of the same two records: - an IMAGE clip boundary of type 1 carries no vertex count; the two corners follow the boundary type directly. The `BL` read there consumed the first 34 bits of the -0.5 corner. - WIPEOUT stores a raster-image record — the IMAGE and WIPEOUT are bit-identical for 175 bits and the IMAGE field list closes the WIPEOUT exactly on its data boundary. `wipeout::Wipeout` is now an alias for `image::Image`. - a MESH face-list count counts `BL` entries, not faces, and edge endpoints are `BL`. Both real MESH records now decode with Euler characteristics 2 and 0. Three bits before the data boundary are documented rather than guessed. Measured with examples/coverage_report.rs over the 19-file corpus: aggregate 1751/484/46 = 76.8% -> 1755/487/39 = 76.9%; R2018 533/166/46 = 71.5% -> 537/169/39 = 72.1%. Closes #42, closes #16
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
sample_AC1032.dwg'sAcDb:Classeslist desynchronised at record 9, so all 194Custom(N)objects on the file — its 33 SCALE records included — stayedUnhandled. The cause is a contradiction inside the ODA spec that the bytes settle.The spec states the class record twice:
max_class_numberBS+RC 0x00+RC 0x00BLdwg_versionBSBLmaintenance_versionBSBLBSandBLare bit-identical on tag10(2 bits, zero) and tag01(10 bits, one byte), and differ only on tag00, whereBStakes an 18-bitRSandBLa 34-bitRL.BS max_class_number+ twoRC 0x00is also 34 bits over the same four little-endian bytes as a tag-00BL, so the header never discriminates. The §10.2 reading therefore survives on any file whose classes keep both version fields under 256 — which is every class onarc_2004,arc_2010andarc_2013.sample_AC1032.dwgis the first file that doesn't:num_objectsdwg_versionmaintenance_versionMLEADERSTYLEACDBDETAILVIEWSTYLEWIPEOUTMULTILEADEREvery other record on that file is 57-89 bits. Reading the
329as aBSconsumes 18 bits instead of 34, so record 8 ran 16 bits long, record 9 hit the reserved11BLtag, and the consecutiveness guard threw the whole table away.The R2018 class-record layout, with evidence
1. The record count lands exactly on the string block. On R2007+ all
3 × Nnames live in one block after the last record, so a list that stops one bit early mis-pairs every name. With the corrected field list, reading exactlymax_class_number - 500 + 1records lands on the block's first bit and the names come out in order (ACDBDICTIONARYWDFLT,ACDBPLACEHOLDER,LAYOUT, …ACDBPERSSUBENTMANAGERon AC1032).2. The §19.4.1 string-stream trailer agrees independently. Its terminating bit is set on all three files and its length word equals the measured span, including the two-word form on AC1032 (
0xB2EChas bit 15 set, second word 1 →(0xB2EC & 0x7FFF) | (1 << 15) = 45804):size_in_bits − 32arc_2010.dwgarc_2013.dwgsample_AC1032.dwg(bit offsets relative to the start of the bit stream.) On the pre-R2007 layout the equivalent check is the declared size:
arc_2004.dwg's ten records consume 5161 of the 5168 bits its header declares, the remaining 7 being byte padding.3.
num_objectsmatches the object walk. The field is now carried onClassDef; summed over the corpus against whatall_objects()walks it agrees exactly on the high-count classes — VISUALSTYLE 240/240, SCALE 186/186, ACDBDETAILVIEWSTYLE 11/11, ACDBSECTIONVIEWSTYLE 11/11, MLEADERSTYLE 11/11, TABLESTYLE 10/10, BLOCKGRIPLOCATIONCOMPONENT 6/6. Where the two disagree (DICTIONARYVAR 104/72, MULTILEADER 15/10, LAYOUT 4/0) the shortfall is on the walk side — objects the handle-map walker doesn't reach — not the class table.examples/probe_class_layout.rsprints all of this:Measured coverage
cargo run --release --example coverage_report -- <19-file samples dir>:65 R2018 records left skipped. 45 of them now decode (the 33 SCALE records among them). The other 20 now reach a decoder and fail: MULTILEADER (10), MESH (3), ACAD_TABLE (2), WIPEOUT, IMAGE, IMAGEDEF, ACDBDICTIONARYWDFLT, DICTIONARYVAR — almost all with
Bit cursor exhausted: wanted 8 bits, 3 bits remaininside the common entity preamble, before any per-entity field is read. That is the R2007+ preamble/handle-stream gap already tracked under #103, now visible on five more classes. Those 20 were always broken; the missing class table was hiding them.Also in this PR
ClassDefgainednum_objects,dwg_version,maintenance_version;write_class_mapround-trips them instead of writing zeros, so the writer is still the exact inverse of the parser — including the oversized-BLcase, pinned by a new BitWriter-built test on both the inline (R2004) and split (R2018) layouts.write_class_map's doc now states plainly where it is not a byte-exact AutoCAD emitter (the size-in-bits header and the string-stream trailer), since neither is read back.examples/coverage_report.rsnames custom classes in its unhandled histogram —VISUALSTYLE (custom class)rather thanCUSTOM(502) (0x01F6). A class number is per-file, so the name is the only meaningful aggregate key; this also merged two entries that were the same class under different numbers on different files.Spec sections
AcDb:Classesfor R2007+:RLsize in bytes,RLtotal size in bits,BLmaximum class number,B, class data, string stream data,B. Record tailBL/BL/BL/BL/BL. This is the description the bytes match.AcDb:Classesfor R18+: theBS+RC+RCheader andBSversion fields. Bit-identical on the observed value range; wrong onsample_AC1032.dwg.max_class_number, no record tail), unchanged here and still unreachable in practice: those releases do not expose the section by name.B/BS/BLtag alphabets, which is what makes the two spec readings collide.Source provenance
Clean-room declaration. I certify that:
CLEANROOM.mdlists as allowed: the freely-redistributable ODA Open Design Specification for .dwg files v5.4.1 PDF (§5.8, §10.1, §10.2, §19.4.1, §2.x), and first-party byte inspection of the publicly-available sample DWGs in the local corpus (nextgis/dwg_sampleslineage plussample_AC1032.dwg). No Autodesk SDK source, no ODA SDK / Teigha source, no LibreDWG, no decompilation of any Autodesk or ODA binary, and no copyleft-licensed DWG implementation code.src/classes.rsmodule docs,ARCHITECTURE.md§7e,examples/probe_class_layout.rs).Gate
cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,cargo test --release(693 lib + all integration suites),cargo deny check all,RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features, andcargo +1.85.0 test --no-run(MSRV) all pass. The canonical-corpus fixtures did not move: the class-map writer change only affects the record tail, which those fixtures do not pin.Closes #37
https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
Note
Medium Risk
Changes bit-level layout for the class table and custom-type dispatch on R2004+; impact is mitigated by consecutiveness checks, round-trip tests, and a fixture for maintenance_version > 255.
Overview
Fixes R2018
AcDb:Classesparsing so custom object types dispatch by DXF name instead of falling through as anonymousCustom(N).The ODA spec disagrees on whether
max_class_number,dwg_version, andmaintenance_versionareBSorBL; the old parser followed §10.2. That matches §5.8 while values stay ≤255, but onsample_AC1032.dwgfour classes usemaintenance_version = 329, which misreads asBSand desynchronizes the table at record 9. The consecutiveness guard then drops the whole map, leaving 194 custom objects undispatchable. The parser andwrite_class_mapnow useBLfor those fields (§5.8), andClassDefcarriesnum_objects,dwg_version, andmaintenance_versionwith writer round-trip.Adds
examples/probe_class_layout.rsfor bit-offset / string-trailer verification, andcoverage_reportlabels unhandled custom types by DXF class name. Corpus aggregate decode rate moves 74.8% → 76.8% on the R2018 sample; error count rises because objects that were skipped now hit decoders and fail in the common entity preamble (#103), not because of a regression.Reviewed by Cursor Bugbot for commit 01b6c84. Configure here.