Repository navigation
fix(entities): close the last 39 R2018 errors — MULTILEADER, HATCH and seven more field lists - #58
Merged
Merged
Conversation
…tors restart per handle section The AcDb:Handles delta run was decoded with two wrong rules, and their combination is what #44 measured as a 96,739-byte address-space shortfall against AcDb:AcDbObjects. 1. The handle delta is an UNSIGNED modular char; only the offset delta is signed. Reading it as signed steals bit 0x40 of the terminating byte as a negation flag, so every single-byte delta in 0x40..=0x7F decoded small and negative. On sample_AC1032.dwg the first divergence is entry 272, after which every handle ran 108 low. 2. Both accumulators restart at zero on every handle section. The first pair of a section is absolute. Carrying the totals across the boundary threw entries 656..841 (186 of 842) into a fabricated address space and produced the phantom offset 1,289,590. The section assembly was never wrong: AcDb:AcDbObjects is 41 pages of 0x7400 decompressed bytes truncated to its declared 1,192,851, and the trailing 24,685 bytes are the last page's zero padding. After the fix the map's highest offset is 1,192,823. Every record repeats its own handle, so the object stream verifies the map against itself. Agreement goes from 272/842 to 842/842, walker skips from 97 to 0, and the walked records cover 1,191,935 of 1,192,851 section bytes (916 unclaimed, longest run 4). BitCursor::read_handle now rejects a counter above 8 with the new Error::HandleCounterTooLarge, surfaced as a walker skip rather than a decoder error so coverage ratios stay comparable. Coverage over the local 19-file corpus: R2018 561/145/39/75.3% -> 712/91/39/84.6%; aggregate 1923/319/39/84.3% -> 2074/265/39/87.2%. Closes #43 Closes #44 Closes #51 Claude-Session: https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
…tities # Conflicts: # CHANGELOG.md # README.md # STATUS.md
…d seven more field lists sample_AC1032.dwg now decodes with zero errors, and so does every other file in the 19-file corpus: 2144 decoded / 234 skipped / 0 errored / 90.2% aggregate, up from 2105 / 234 / 39 / 88.5%. - the `strings present` trailer bit is not an entity field, so a record with no string stream ends one bit before data_section_end - object references consume no data-stream bits (MULTILEADER, HATCH, UNDERLAY read them inline) - MULTILEADER embeds a whole MLeaderAnnotContext (SS20.4.48 + SS20.4.86) - the HATCH gradient block is unconditional and its flag is a BL - INSERT data flags, SPLINE derived scenario + BL degree, LWPOLYLINE flag bits, 3DFACE 3DD corners, IMAGEDEF 2RD, DIMENSION ang-2-line 16-point first, LTYPE dash record, UNDERLAY field order - MTEXT's R2018 redundant/column block and ATTRIB's embedded MTEXT Closes #57, closes #30, closes #29
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_cba9c309-41c2-42f9-bae2-b1e1c25b7f32) |
This was referenced Aug 30, 2026
This was referenced Oct 21, 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
sample_AC1032.dwgnow decodes with zero errors, and so does every other file in the 19-file corpus. The 39 records that still failed after #52 and #53 — MULTILEADER 15, HATCH 8, INSERT 4, LTYPE 3, SPLINE 2, and one each of 3DFACE, LWPOLYLINE, DIMENSION_ANG_2LN, ATTDEF, ATTRIB, IMAGEDEF and PDFUNDERLAY — are all decoded, each by a decoder that checks itself against the record's data-stream boundary.That check is the point. Every R2007+ decoder here must land its data fields exactly on the first bit of the record's string stream, or — for a record that carries no strings — on the bit before the
strings presenttrailer flag. A field list that is wrong anywhere lands somewhere else and errors. Zero errors therefore means zero known mis-reads, not zero unchecked reads.DIMENSION,MTEXTandHATCHare moved off the weaker<= string_startassertion onto exact equality as part of this.Measured coverage (
examples/coverage_report.rs, 19-file local corpus)Both columns measured on this machine: the "before" column on a detached worktree at
fa7fcc8(origin/main), the "after" column on this branch after merging it.fa7fcc8)The three older bands are untouched — no record of theirs changes bucket. What remains corpus-wide is the skipped column: 234 records of types with no field list matched against real bytes yet (VISUALSTYLE on R2004/R2007, MATERIAL, MLEADERSTYLE, MLINESTYLE, TABLESTYLE, the detail/section view styles).
The finding that unblocked four of the nine entity types
The
strings presenttrailer bit is not an entity field. A record with no string stream still writes the one-bit flag that says so; it is the last bit before the handle stream, and it belongs to the trailer, not to the record's field list. So such a record's data fields end one bit beforestring_stream::data_section_end.All 20 LWPOLYLINEs, the 3DFACE, the four INSERTs and the two SPLINEs of
sample_AC1032.dwgcarry no strings, and every single one ended its field list exactly one bit short of the old boundary — a uniformdelta -1across four unrelated field lists. Modelling that as a trailingBper entity would have put a fabricated field at the end of each. Newstring_stream::data_field_endreturns the string-stream start bit when there is one anddata_section_end - 1when there is not;object::data_end_bitandtables::modern::open_entityboth route through it, and two tests instring_stream.rspin both branches.Per-entity bit evidence
MULTILEADER — 15 records (§20.4.48 + §20.4.86)
§20.4.48 says it outright: "A significant portion (content block/text and leaders) of the multileader entity is stored in the MLeaderAnnotContext object (see paragraph 20.4.86), which is embedded into this object (stream)." So the record reads
BS 270version, then the whole context field list inline, then the style block.Three things the spec's own tables settle, each confirmed by the boundary:
AcDbAnnotScaleObjectContextData(§20.4.71) →AcDbObjectContextData(§20.4.89) — aBSversion, twoBflags and anH. None of it is present: on handle0x7B8the version reads2at bit 6885 and the next 10 bits are aBLof1(one leader root), after which the twoBflags, a full-double connection point and a(1, 0, 0)direction all land. Reading the inherited prefix first puts the connection point 12 bits late and it decodes as a reservedBDpattern.-R2007arrowhead / block-label block is genuinely absent on R2018. Nothing is lost: in R2010+ the arrowhead moved into the leader line (H 341arrow symbol per line).Hconsumes zero data-stream bits. MLEADER previously read three of them inline, which is what MLEADER reads three H handles inline on R2007+, misaligning before its TV fields (10 records of real text unread) #31 diagnosed.Value corroboration, all read from the string stream at the slot the field list predicts:
"MLeader text, hello!"(0x7B8),"MULTILEADER TEST"(0xB1A,0xB27),"MULTILEADER\PTEST\P123"(0xB1B). Geometry corroborates too —0xB1Areads landing distance8, arrowhead size4, content type2(MTEXT), block scale(1, 1, 1), override flags279552=1<<10 | 1<<14 | 1<<18(content type, text alignment, use-default-MTEXT), and top/bottom attachment9/9.Not established, and marked as such in the code: 17 bits sit between
B 293 is annotativeand the R2010+BS 271that §20.4.48 does not list — anMC(two bytes on all 15 records) then aB. TheMCholds only274,530and786across the whole file (18 + 128·{2,4,6}) and theBistrueon every record.B+RS, orB+ twoRCs, consume the same bits on every record here, because each byte pair happens to have the continuation bit set on the first byte and clear on the second;MCis taken because it is the only one of the three that stays correct if a record ever carries a larger value. Which of the threeBs in that run isis annotativeis also undecidable from this corpus — the decoder keeps §20.4.48's order and surfaces the other two asMLeader::undocumented_mc/undocumented_flagrather than inventing names.HATCH — 8 records (§20.4.75)
The gradient block is unconditional on R2004+: §20.4.75 lists
Is Gradient Fillas aBL(not theBSthis crate read) and does not guard the rest of the record behind it. All eight HATCH records of the sample carry two strings in their string stream —"LINEAR"then the pattern name ("ANSI31","AR-PARQ1","SOLID,_O","HSBDR3E0","HVEGE100") — even though six of them have the flag clear. Returning early on a clear flag consumed oneTVtoo few and shifted the entire boundary-path tree; that is thenum_boundary_handles count 3254780159in #30.Four more corrections from the same section, each needed for a record to close:
BLcount (#30)BDpairs2RD— raw doublesBS stylethen straight to the pattern angleBS pattern typesits between themif (!solidfill)BS pixel_sizealways readBD, written only when some path flag has bit4setThe pattern-line cap moves 100 → 4096:
"HVEGE100"(handle0xBC4) legitimately declares 232 definition lines, and closes exactly.INSERT — 4 records (§20.4.9)
The
BBdata flags select one of four scale encodings, none of them theBDtriple this crate read:11=(1,1,1)with nothing stored,01= x is 1.0 plus twoDDs,10= x as anRDwith y = z = x,00= x as anRDplus twoDDs defaulting to x. The extrusion is a3BD, not aBE. TheBLowned-object count is written only whenhas_attribsis set.0x660100x661100xC9E100x79C10LTYPE — 3 records (§20.4.58)
The dash record is
BDlength,BScomplex shapecode,RDx-offset,RDy-offset,BDscale,BDrotation,BSshapeflag — two raw doubles in the middle, and the shape flag after the geometry. TheX 9text area is 512 bytes on R2007+ and present only when some dash setsshapeflag & 0x02; all three failing records have it clear on every dash. The modern path also drops its heuristic string-scanning fallback and goes throughtables::modern::open_table_entrylike every other table entry.SPLINE — 2 records (§20.4.40)
Degreeis aBL, not aBD. And on R2013+ the fit/control branch is derived, not read: "the scenario flag becomes 1 if the knot parameter is Custom or has no fit data, otherwise 2".0x4330,0,0,0,1,1,1,1, 4 control points0x4341e-10, 2 fit pointsBoth store
1; one is a fit spline.LWPOLYLINE — 1 record (§20.4.85)
The flag bits are
0x001normal,0x002thickness,0x004constant width,0x008elevation,0x010bulges,0x020widths,0x400vertex ids — and the constant width is read first, right after the flag, not after the counts. 19 of the sample's 20 records carry flag0or0x200and survive either reading; handle0x4A6carries flag4, and under the old reading thatBDwas an extrusion three fields later, which put the vertex count on a reserved11pattern.0x200is not one of §20.4.85's presence bits and twelve records carry exactly it with no optional field at all; it is read as the closed flag, which is the conventional meaning — nothing in this corpus contradicts it and nothing proves it.3DFACE — 1 record (§20.4.32)
Corners 2-4 are
3DDtriples defaulting componentwise to the previous corner, notBDoffsets added to it, and all four corners are always present — only the invisible-edgeBSis conditional onhas_no_flag_ind. Handle0x322closes at bit 503.IMAGEDEF — 1 record (§20.4.81)
ImgsizeandPixelsizeare2RD. Read asBDs, handle0x8C4lands on a reserved11pattern.DIMENSION (angular, 2-line) — 1 record (§20.4.27)
The
2RD16-point comes first, before the four3BDdef points. Handle0x516closes at bit 1129 with that order and hits a reservedBDpattern without it.PDFUNDERLAY — 1 record (no spec section)
The v5.4 spec has no UNDERLAY chapter, so this field list is measured from bytes alone. Handle
0xD07closes exactly at bit 381 with3BDnormal,3BDinsertion point,BDrotation,3BDscale,RCflags,RCcontrast,RCfade,BSclip-vertex count — and every value it yields is self-consistent: unit normal(0, 0, 1), insertion(16.2869…, 15, 0), zero rotation, unit scale(1, 1, 1), flags3(clip on + underlay on), contrast100, fade0. The previous order put the scale on(0, 0, 1)and the normal on(1, 1, 1), then read the definition handle inline. Not established: the clip-vertex encoding — the record carries none, and the sibling IMAGE uses2RDfor its clip boundary.Two issues closed on the way
#29 — MTEXT's 567 undecoded bits. §20.4.46 has an R2018+ block after the background flags: a
B"is NOT annotative" and, when set, a version, a default flag, a handle slot, and a redundant copy of the record's own attachment point, x-axis, insertion point, rectangle and extents, then the column block. That is exactly why #29's probe found the tail repeating the record's own values. Handle0x513closes at bit 773 withis_not_annotative = true, version4, attachment point7, x-axis(1,0,0), insertion(741.02…, 14.70…, 0), extents16.374 × 1.845, column type0. MTEXT now asserts exact equality instead of<= string_start, and surfacesis_annotative,column_type,column_width,column_gutter,column_heights. The background block is also entered on the R2018 text-frame bit0x10, per the same section.#30 — HATCH boundary paths. Above.
#31 is the MLEADER handle-stream diagnosis; it is subsumed by the MULTILEADER work here but left for the maintainer to close alongside #57.
ATTRIB / ATTDEF (§20.4.4, §20.4.5)
An R2010+
RCversion and an R2018+RCattribute type sit between the shared TEXT body and the attribute's own fields. A multi-line attribute (type != 1) then embeds a whole MTEXT record "starting from the Entmode (entity mode)" — no length, no type code, no handle, no EED chain, no graphics block.0x7050x79F0x7A00x79D"my multi line text for the attrrib","MULTI_LINE_ATT"0x6F8/0x797/0x798/0x799(ATTDEF)0x796(ATTDEF)ATTDEF is "Common ATTRIB Entity Data" plus its own
RCversion and aTVprompt. The lone unexplainedRCthe old ATTDEF field list carried after the lock bit was that version byte, and the two bytes §20.4.4 puts before the tag were missing entirely — three bytes cancelling to one, which is why the old list closed on the four single-line ATTDEFs and failed on the multi-line one.#54 — measured, not settled
Exactly three entity records in the corpus set the R2013+
has AcDs binary databit: 3DSOLID0xD65and0xD6A, and REGION0xD69. All three are ACIS pass-through decoders whose field lists this crate does not close, so they cannot arbitrate the marker width either — I probed0xD69under both the 0-bit and 16-bit readings and neither is decidable from a record whose tail is undecoded. None of the 39 records fixed in this PR sets the bit, so the reading did not matter for any of them, andcommon_entity.rsis unchanged in that respect. Settling #54 still needs a file with a flag-setting record of a type whose field list closes.Probes added
examples/probe_decode_errors.rs— every erroring record with its handle, type label, body-start bit, data boundary and the bit budget between them. This is the granularity a field-list investigation needs andcoverage_reportdeliberately does not print.examples/probe_entity_field_list.rs— the entity-side twin ofprobe_field_list: walks a candidate token list against one entity record past its common preamble and prints the delta from the boundary.HandTVslots consume no data bits on R2007+;TEXTFIELDS,MTEXTFIELDSandENTMODEcomposites walk the shared bodies;--at=<bit>starts the walk at an absolute offset so a tail hypothesis can be tested without re-describing everything in front of it.Spec sections
§19.1 (split streams), §20.4.1 (common entity data), §20.4.4 (ATTRIB), §20.4.5 (ATTDEF), §20.4.9 (INSERT), §20.4.27 (DIMENSION angular 2-line), §20.4.32 (3DFACE), §20.4.40 (SPLINE), §20.4.46 (MTEXT), §20.4.48 (MLEADER), §20.4.58 (LTYPE), §20.4.71 / §20.4.86 / §20.4.89 (
MLeaderAnnotContextand its bases), §20.4.75 (HATCH), §20.4.81 (IMAGEDEF), §20.4.85 (LWPLINE), §2.11 (CmColor).Source provenance
Clean-room declaration. Every layout in this PR was derived from the Open Design Alliance's freely-redistributable Open Design Specification for .dwg files v5.4 plus a bit-level walk of
sample_AC1032.dwg. No LibreDWG, ODA SDK / Teigha, or Autodesk SDK source was read; no decompilation was consulted; no permissively-licensed DWG implementation source or comments were consulted for this change. Where the spec is silent — the UNDERLAY field list, the 17 undocumented MULTILEADER bits, the LWPOLYLINE0x200bit, the UNDERLAY clip-vertex encoding — the code says so in place rather than guessing, and the PR text above repeats each one.CLEANROOM.mdis unchanged because there is nothing new to disclose.Gates
cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,cargo test --release(722 lib tests + 16 integration suites, all green),cargo deny check all,RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features,cargo +1.85.0 test --no-run— all pass. Every newpub fncarries a///line.New BitWriter-built R2018 tests, one or more per fixed decoder: MULTILEADER round-trip + misalignment rejection, HATCH split-stream two-name test + clear-flag regression guard, INSERT for all four data-flag forms plus a boundary-checked ATTRIB-carrying record, SPLINE control/fit/derived-scenario/misalignment, 3DFACE triangle + quad, LTYPE name-and-description + dash record, MTEXT R2018 annotative block + dynamic columns + truncation rejection, ATTRIB multi-line embedded MTEXT, ATTDEF single-line, and two tests pinning both branches of
string_stream::data_field_end.Closes #57
Closes #30
Closes #29
Refs #31
Refs #54
Note
Medium Risk
Large, behavior-changing binary layout fixes across many public entity types and structs; risk is mitigated by exact boundary self-checks and expanded tests, but consumers depending on old field shapes or partial decode success may see different parsed values.
Overview
Eliminates all 39 remaining decode errors on
sample_AC1032.dwgand brings the 19-file corpus to 0 errored records (2,144 decoded / 90.2%), by aligning R2007+ entity decoders with the real data-stream boundary.Shared plumbing:
string_stream::data_field_endtreats the one-bit “strings present” trailer as outside the field list (string-less records end one bit early). Dispatch routes more types through exact boundary checks;HandTVslots consume no data-stream bits.read_entity_mode_onwardssupports embedded MTEXT inside multi-line ATTRIB/ATTDEF.Decoder fixes: MULTILEADER (embedded annot context, split-stream path,
DecodedEntity::MLeaderboxed). HATCH (unconditional gradient +BLflag,2RDgeometry, conditional pattern block, boundary handle count only). INSERT (BBscale encodings,3BDextrusion, conditional owned count). Plus corrected field lists for SPLINE, LWPOLYLINE, 3DFACE, IMAGEDEF, DIMENSION (2-line angular), LTYPE, UNDERLAY, MTEXT R2018 tail, and ATTRIB/ATTDEF with optional embedded MTEXT.Adds
probe_decode_errorsandprobe_entity_field_list; updates ARCHITECTURE, CHANGELOG, README, and STATUS with measured coverage.Reviewed by Cursor Bugbot for commit 606bb82. Configure here.