Repository navigation
fix(entities): hold every entity type to its exact data-stream boundary (2262/116/0 → 2273/96/9) - #69
Merged
Merged
Conversation
Until now only the entity types that had to know about the R2007+ split streams asserted anything about where their fields end. The POLYLINE family, MESH, IMAGE, WIPEOUT, VIEWPORT, LEADER, MLINE, the four SURFACE variants, RAY, XLINE, POINT, CIRCLE, ARC, LINE, ELLIPSE, SOLID, TRACE, ENDBLK and BLOCK decoded with no boundary check at all — and on the R2000/R2004 band, so did every entity type. Their zero error count was a property of the dispatcher, not of the bytes. Every fixed-code and custom-class entity decoder now runs through `checked_inline`, which requires the field list to end exactly on the record's own data-stream boundary: the string-stream start bit (or the handle-stream start minus the `strings present` trailer bit) on R2010+, and the `RL` object-data-size-in-bits on R2000/R2004. On R2010+ no entity type decodes unchecked any more. Three field lists the check caught, each fixed to delta 0 with an independent value corroborating it: - BLOCK (45 records) read its one TV inline; on R2010+ the name lives in the string stream and the record's budget is 0 bits. Names now decode as *Model_Space, _ArchTick, MyBlock — matching their BLOCK_RECORDs. - POLYLINE_PFACE (1) claimed five BS counts and two inline H handles, overrunning by 52 bits; the record holds BS 5, BS 2, BL 7 in 30 bits, and the file carries exactly 5 VERTEX_PFACE + 2 VERTEX_PFACE_FACE. - MLINE (3) read num_lines as BS where the record writes one RC. Five previously-Unhandled types now decode, proved rather than assumed: SEQEND, POLYLINE_3D, VERTEX_3D/VERTEX_MESH/VERTEX_PFACE and VERTEX_PFACE_FACE. Handles 0x422..0x431 of sample_AC1032.dwg read back as a self-consistent chain whose declared counts match the records that follow them. Three decoders fail the check and are reported, not patched: VIEWPORT (6 records, delta -819 — the decoder reads 266 of 1125 bits by design), MESH (2, delta -2 — two trailing bits reading `10`, the zero code of BS, BL and BD alike) and LEADER (1, delta -12). Corpus: 2262 / 116 / 0 / 95.1% -> 2273 / 96 / 9 / 95.6%. Closes #63
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_a14d1b83-b127-417c-a889-f66cc016c678) |
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.
What this does
Until now only the entity types that had to know about the R2007+ split streams asserted anything about where their fields end. Everything else decoded with no boundary check at all — the POLYLINE family, MESH, IMAGE, WIPEOUT, VIEWPORT, LEADER, MLINE, the swept/lofted/extruded/revolved surfaces, RAY, XLINE, POINT, CIRCLE, ARC, LINE, ELLIPSE, SOLID, TRACE, ENDBLK, BLOCK — and on the R2000/R2004 band, every entity type. Their zero error count was a property of
dispatch.rs, not of the bytes.Every fixed-code and custom-class entity decoder now runs through
entities::dispatch::checked_inline, which requires the field list to end exactly on the record's own data-stream boundary:string_stream::data_field_endRLobject-data-size-in-bits from the object prologueRawObject::obj_size_bitsRLspans data and strings and this crate cannot locate an AC1021 string stream yet (#110)On R2010+ the number of entity types that decode unchecked is zero. Neither unchecked band has a record that reaches a decoder at all.
checked_inlinealso hands the decoder the record's string reader now, which is what let BLOCK stop reading its name inline; the six R2010+-only special cases indispatch_split_stream_entity(INSERT, 3DFACE, LWPOLYLINE, 3DSOLID, REGION, BODY) collapsed into the general path, which is identical.Per-type table
Corpus is the local 19-file
samples/set. "before" is7b2afe2(main with #64).TVinline — fixed, delta 0 on all 54BS→RCone-token fix, delta 0, 3/3Unhandled— 160-bit budget, no field listTOLERANCE is confirmed exact (per #28): all 3 R2018 records go through
tolerance::decode_modern_split_stream, delta 0. TEXT's reading is untouched (#62'sBD-vs-RDcaveat): all 29 records close at delta 0 with a 202-bit budget, which means every one of them sets the DataFlags bits that suppressoblique_angle/rotation_angle/width_factor— so no record arbitrates #62 and it stays open.New-error census, with evidence
cargo run --release --example probe_decode_errors -- samples/sample_AC1032.dwg:0x240,0x245,0x252,0x256,0x267,0x26Bentities/viewport.rsis an admitted prefix decoder (BD3 center, BD width, BD height). Six records of one identical shape give no variation to separate candidate token sequences with, so no field list is guessed.0x343,0x38010on both records — the zero/default code ofBS,BLandBDalike. A zero corroborates nothing, so under the #58 rule this is "documented offsets and stop". The module's older note said "3 bits" — that counted thestrings presenttrailer flag, which is not an entity field; corrected.0x512BDs and trailingBs summing to 12), on a single record.Net effect on the corpus: 9 errored, up from 0. That is the point of #63 — the same nine records "decoded" before, with nothing checking that they had.
Fixes made (each
delta 0+ independent value corroboration)BLOCK — the
TVis in the string stream on R2010+. Budget measured with the newexamples/probe_entity_budgets.rs: 0 bits on 27/27 R2018 records and 3/3 on each ofarc_2010.dwg/arc_2013.dwg. Reading the name inline overran on all 33 (deltas +58 … +266). Corroboration: the names now decode as*Model_Space,*Paper_Space0,_ArchTick,*D3,MyBlock— matching the BLOCK_RECORD entries they pair with, which come from a different stream. The 9 R2004 records spend 114-122 bits there (inlineBSlength + NUL-terminated name) and close on theirRLwith the unchanged inline reading.POLYLINE_PFACE —
BS,BS,BLin 30 bits, not 5×BS+ 2 inlineH. Handle0x422, budget 30 bits,probe_entity_field_list … BS,BS,BL→5,2,7, delta 0. Corroboration: the file carries exactly 5 VERTEX_PFACE (0x423..0x427) and 2 VERTEX_PFACE_FACE (0x428,0x429) records, summing to theBL 7owned-object count. The two inlineHreads were the bulk of the +52 overrun — an object reference never occupies data-stream bits from R2000 on.MLINE —
num_linesis anRC. WithBSall three records (0x38B,0x3A5,0x3A6) decodelines = 521,verts = -11716and die. One token changed; all three land at delta 0 withnum_lines = 2,num_verts8/2/2, justification Zero/Top/Zero and scale 1.5 / 2.13 / 1.598 — plausible values where the old reading produced a negative count.Newly decoded types (previously
Unhandled)Handles
0x422..0x431ofsample_AC1032.dwgare contiguous and read back as one self-consistent chain, which is the corroboration for all five at once:Every declared count matches the records that follow it. The face indices are all inside the mesh's declared 1..=5 range, with the negative-index invisible-edge convention and a
0terminating the three-corner face. The flag bytes name themselves against the flag table already inentities/vertex.rs:0x20is "3D polyline vertex",0xC0is "polyface mesh vertex" + "3D polygon mesh vertex". None of that comes from the bit budget.BSandBLare indistinguishable for a value below 256 (both spend01plus one byte), so the owned-object counts are read as theBLtables::block_recordalready uses for the same purpose; only the width and the value are claimed.The three deliberately-undetermined readings (recorded, unchanged)
Gathered into one table in ARCHITECTURE §7i, plus MESH's new one:
MC+BvsB+RSvsB+ twoRCs; theMCholds only274/530/786across 15 records and theBistrueon allRSrange, or whoseBis false2BDvs2RD— the one corpus record has a zero clip-vertex count so no vertex is ever read0x2000x200set and an optional field present10(new)BS0,BL0,BD0.0 and "two spare bits" encode identicallyAlso in this change
POLYGON_MESHstops reading twoHhandles from the data stream. No corpus record exercises this type, so its list stays otherwise unverified and the module now says so; the removal is justified by the crate-wide invariant, not by a measurement of this type.examples/probe_entity_budgets.rs(new) — prints, for every entity record, the bit budget its field list has to fill. This is the tool the whole PR was derived from;probe_decode_errors.rsonly shows records that already error, which is no help for a type with no decoder at all.examples/dump_decoded_entities.rsprints the six new variants.Measured coverage
The three unchanged slices are the interesting ones: their counts did not move, but every entity record in them is now checked where none was before, and every one passes. The CI
coverage-smokecorpus (tests/fixtures/canonical) stays at 20/0/0/100 %.Gate
cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,cargo test --release(751 lib + all integration suites green — the canonical-corpus pins are unchanged, the synthetic fixtures already satisfied the new boundary check),cargo +1.85.0 test --no-run,cargo deny check all,RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features— all pass.Follow-ups
BLOCK_RECORDdecodes*D/*T/*Paper_Spacewhere the BLOCK beside it decodes*D3/*T9/*Paper_Space0. Both come from string streams; one of the two is reading a different slot. Noticed while corroborating the BLOCK fix, not investigated here.BDvsRD) remains unarbitrated: every corpus TEXT record suppresses the three fields.Unhandledbecause they decode "only a documented prefix" — that is a one-line change tofixed_entity_label. I left it as an error because Extend the exact-boundary check (checked_inline) to every remaining entity type — their error count is structurally zero today #63 asks for the honest error, and because MESH and LEADER (delta −2, −12) are genuinely near-complete lists rather than prefixes.Clean-room declaration. I certify that:
CLEANROOM.md. 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. Every field list added or corrected here was derived from the corpus bytes: the record's own data-stream boundary, the values that land on it, and the object stream's own counts. No outside vocabulary was needed —flags,vertex_count,face_count,num_owned_objects,locationandvertex_indicesare the names already used by the sibling modules in this crate.Closes #63
Note
Medium Risk
The change refactors the central entity dispatch path for every type and alters reported decode success (nine new errors), so regressions in geometry or coverage are possible despite added tests.
Overview
This PR routes all fixed-code and custom-class entity decoders through
entities::dispatch::checked_inline, so field lists must end exactly on each record’s data-stream boundary (R2010+ string-stream start or handle trailer; R2000/R2004RLobject-data-size). R2010+ no longer has any entity type that decodes without that check.Fixes with
delta 0: BLOCK reads its name from the string stream on R2010+ (was inlineTV); POLYLINE_PFACE isBS/BS/BLcounts without inline handles; MLINE usesRCfornum_linesinstead ofBS. New decoders: SEQEND, POLYLINE_3D, VERTEX_3D/MESH/PFACE, VERTEX_PFACE_FACE. POLYGON_MESH drops two inlineHreads from the data stream (same rule as polyface).Intentional errors (9 records): VIEWPORT (−819 bits, prefix decoder), MESH (−2 trailing bits), LEADER (−12 bits)—documented, not guessed. Corpus coverage moves from 2262 / 116 / 0 to 2273 / 96 / 9 (95.1% → 95.6%); R2004–R2013 counts unchanged but every entity there is now boundary-checked.
Adds
examples/probe_entity_budgets.rsand extendsdump_decoded_entitiesfor the new variants; docs (ARCHITECTURE §7i, README, STATUS, CHANGELOG) reflect the new honesty model.Reviewed by Cursor Bugbot for commit 376905d. Configure here.