Repository navigation
fix(entities): the R2010+ entity graphics-preview block is sized by a BLL, not an RL - #46
Merged
Merged
Conversation
… BLL 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
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_f961467a-458d-4dd4-83de-8e6077019ae7) |
This was referenced Aug 30, 2026
Closed
4 of 6 tasks
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 R2007+ common entity preamble did not diverge for custom-class entities. It diverged for entities that carry a graphics-preview block, and on R2018 that block's size field is a
BLL(§2.4), not theRLused up to R2007.AutoCAD writes proxy graphics for entities whose class it does not implement natively, so the
graphics presentflag (§19.4.1) is set on exactly MULTILEADER / MESH / ACAD_TABLE / WIPEOUT / IMAGE and clear on LINE / TEXT / MTEXT. That is the whole correlation withCustom(N). Nothing in the class record —was_a_proxy,is_an_entity, proxy flags, class-specific headers — changes the preamble field list.Read as an
RL, the size came back as 6,946,890 / 8,425,777 / 8,388,672 bytes for records a few hundred bytes long, and the byte-skip loop ran off the end of the record before any entity-specific field:Bit cursor exhausted: wanted 8 bits, 3 bits remain.Bit evidence
3Bis three raw bits, not a stop-at-zero prefix code. The old reading could produce only{0, 2, 6, 7}— a set with no encoding for "one byte", which the file requires.0x662001+8C0x44D001+8C0x66E010+50 030x818010+98 020x343010+28 250x380010+08 24The check is what follows the block. Every one of those records then reads
entmode = 2,num_reactors = 0,no_xdictionary = true, colour0x0100, linetype scale1.0, all flag fields0,invisibility = 0,lineweight = 0x1D— bit for bit the values every plain LINE / TEXT / MTEXT record in the same file carries. With the oldRLreading not one of them reaches a plausible tail.New probe
examples/probe_entity_preamble.rstraces any record's preamble under both readings and prints the bits left to its data boundary.Three body fixes that fall out of the same two records
An IMAGE clip boundary of type 1 (rectangle) carries no vertex count. The two corners follow the boundary type directly. The
BLthe decoder read there consumed the first 34 bits of the-0.5corner of the IMAGE at0x662, silently returning a wrong rectangle and running 33 bits past the record. Measured: corners(-0.5, -0.5)and(993.5, 964.5)on a 994 × 965 raster, bits 1663..1919 of a record ending at 1920. The polygon form (type 2) does carry the count — the WIPEOUT reads4there, then fourRD2vertices spanning 1673..2185 of a record ending at 2186.WIPEOUT stores a raster-image record. The IMAGE and the WIPEOUT are bit-identical for their first 175 bits, and the IMAGE field list closes the WIPEOUT exactly on its boundary (insertion
(271.921…, 3.988…, 0), u/v length31.7077…, brightness/contrast/fade50/50/0, polygon clip with 4 vertices). The previous WIPEOUT field list (BL clip_state,BScount,BD2vertices,B show_clipped, threeRCs) matched no part of those bytes — it was decoding the graphics-preview payload as geometry.entities::wipeout::Wipeoutis now an alias forentities::image::Image;wipeout::decodetakes aVersion.A MESH face-list count counts
BLentries, not faces, and edge endpoints areBL, notBS.0x3430x380The Euler characteristics (2 = closed surface, 0 = one-handle torus) are the independent check.
decodenow rejects any face index or edge endpoint outside the vertex cage, and the crease array reads its ownBLcount. Three bits before the data boundary are left unread and documented, not guessed: both records hold100there, consistent with a trailingBLof 0 plus one padding bit, but two records that both encode zero cannot distinguish aBLfrom aBSfrom two spare bits.MULTILEADER and ACAD_TABLE bodies are deliberately left alone: MULTILEADER's ten failures are now inside the MLEADER body (#31), and ACAD_TABLE has no decoder and reports as
Unhandledwith its class name.Measured coverage (examples/coverage_report.rs, 19-file corpus)
All 20 preamble errors are gone. The R2018 error histogram is now MULTILEADER 10, HATCH 5, INSERT 3, LTYPE 3, DIMENSION_DIAMETER 2, SPLINE 2, long tail 14 — no
Bit cursor exhaustedinside a preamble except the one bogus MESH record described below.#44 CUSTOM(727) — investigated, and it is not a type-code bug
The three records read
tag = 01,RC = 0xE7,+ 0x1F0= 727. That is exactly what the bytes say and the documented R2010+ dispatch. They are not objects at all:0x1607@ 433069 decodes a handle field withcounter = 11— an 11-byte handle value, which cannot exist;0x15E6@ 1063953 decodescode 9, counter 0, value 0, and claimsMS = 29,927bytes withMC = 14,220bits of handle stream;0x13E2→ CUSTOM(517) and0x13E7→ CUSTOM(564), the latter claimingMC = 280,720bits.The root cause is upstream of the type read: the handle map addresses offsets up to 1,289,590 while
AcDb:AcDbObjectsassembles to 1,192,851 bytes — its own declared decompressed size — and six handle-map offsets already fall past the end. The remaining garbage records are offsets that land inside the buffer but on the wrong bytes. That belongs with #43, andread_object_typeis left untouched.Also in this PR
examples/coverage_report.rsnames the type in its error histogram, resolving custom classes through the file'sAcDb:Classestable the way the unhandled histogram already did. Closes #16.Spec sections
§2.1 (
3B), §2.4 (BLL), §19.1 (object prologue / string stream), §19.4.1 (common entity data), §19.4.35 (AcDbRasterImage), §19.4.66 (AcDbSubDMesh).Source provenance
Clean-room. Every layout in this PR was derived from the ODA Open Design Specification v5.4.1 plus a bit-level walk of
sample_AC1032.dwg; no LibreDWG, ODA SDK, or Autodesk source was read, and no permissively-licensed source or comments were consulted for this change.CLEANROOM.mdis unchanged because there is nothing new to disclose.Gates
cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings,cargo test --release(16 suites green),cargo deny check all,RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features,cargo +1.85.0 test --no-run— all pass.Test pins moved with the measurement, each with the reason in place: the
3Bvalue set ({0, 2, 6, 7}→0..=7) inbitcursor,bitwriter,tests/proptest_roundtrip.rsandtests/mutation_failure_modes.rs; the IMAGE rectangle fixture (dropped its vertex count); the MESH fixture (face-list sizing,BLedges, explicit crease count).tests/canonical_corpus.rsis untouched and green — the synthetic fixtures carry no graphics-preview block.Closes #42, closes #16
Note
Medium Risk
Changes core bit primitives (
3B/BLL) and the shared entity preamble used by every decoder on R2010+; wrong semantics would misalign all entities with graphics preview, though tests and real-DWG probes target the measured layouts.Overview
Fixes #42 by reading the common entity preamble’s graphics-preview byte count as
BLLon R2010+ (stillRLthrough R2007) instead of always usingRL, which blew up preview sizes and exhausted the bit cursor on proxy-graphic entities (IMAGE, WIPEOUT, MESH, MULTILEADER, ACAD_TABLE).3Bis now three raw bits (0..=7), not a stop-at-zero prefix, soread_bll/write_bllcan encode one-byte lengths; writers emit the exact byte count.Follow-on body fixes on R2018: IMAGE rectangle clips skip the vertex count; WIPEOUT decodes as
Image; MESH treats the face list as aBLentry count, usesBLedge endpoints, and reads creases from their ownBLcount (with index bounds checks).Adds
probe_entity_preambleand updatescoverage_reporterror histograms to resolve custom classes by DXF name. Corpus coverage moves from 46 → 39 errors onsample_AC1032.dwg(72.1%); remaining MULTILEADER failures are in the MLEADER body, not the preamble.Reviewed by Cursor Bugbot for commit f1569a4. Configure here.