Repository navigation
fix(tables): resolve a block's name through its BLOCK sentinel, and gate the class census in CI - #75
Merged
Conversation
…nd-census-gate # Conflicts: # src/tables/block_record.rs
…ate the class census in CI BLOCK_RECORD decoded *D / *T / *Paper_Space where the adjacent BLOCK entity of the same definition decoded *D3 / *T9 / *Paper_Space0. Both closed their own boundary, so nothing errored — eight BLOCK_HEADERs of sample_AC1032.dwg came back named *D, which no symbol table can hold. Neither reader was on the wrong slot: the BLOCK_HEADER stores only the stem of an auto-generated name and the numeric suffix lives solely on the BLOCK sentinel. AutoCAD's own DXF twin of arc_2013.dwg names the two paper-space BLOCK_RECORDs *Paper_Space and *Paper_Space0 where both DWG records store *Paper_Space. - block_sentinel_handle_of reads the BLOCK handle out of a BLOCK_HEADER's handle stream via the §20.4.52 NULL anchor. - graph::resolve_block_names performs the join: 27 of 27 definitions on sample_AC1032.dwg, 3 of 3 on every R2000-R2018 corpus file. - The R2007+ BLOCK_HEADER decoder moves onto tables::modern::SplitStream and is held to its string-stream boundary, replacing a name-scoring heuristic. - probe_class_census gains --strict and a documented allowlist; CI runs it over every canonical fixture, canonical_corpus.rs asserts the census exactly, and class_census.rs ratchets the real corpus. - The 916 unclaimed object-stream bytes are each record's leading MC field, not padding: 841 of 841 agreements. The stream is 100 % accounted for. Closes #70 Closes #56 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_abbc8975-8040-4ebe-8a74-de34a355be31) |
This was referenced Aug 30, 2026
DrunkOnJava
added a commit
that referenced
this pull request
Aug 30, 2026
…e is not always a live census (#80) * fix(container): a record's MS excludes its own MC, and the class table is not always a live census #77 — the walker's raw slice ended one MC width short on every R2010+ record. #75 measured that each inter-record run in AcDb:AcDbObjects equals the width of the *preceding* record's leading MC handle-stream- size field (841/841 on sample_AC1032.dwg, 100% on three more files, against 734/841 for the following-record reading, with only 8 of the 916 bytes zero). A record is framed `MS | MC | MS bytes | CRC`, so RawObject::raw is now sized mc_width + size_bytes; size_bytes still reports the MS verbatim. string_stream::data_section_end drops its `+ mc_field_bits` correction, which existed only to compensate for the short slice — the rule is now `payload_bits - handle_bits` and the two edits cancel to the same bit offset. Coverage over the 19-file corpus is byte-identical before and after: 3695 / 741 / 9 / 83.1%. Two things the short slice hid: the sequential (handle-map-less) walk drifted by one MC width per record on R2010+, and the object stream looked gappy. Every R2004+ corpus file now tiles exactly — sample_ AC1032.dwg goes from 916 unclaimed bytes to the 4-byte 0x0dca prologue, with zero bytes between records. examples/build_fixtures writes the same rule, and now also emits the §19.1 "strings present" trailer bit with the MC recording the padding that stands in for the handle stream; declaring a zero-bit handle stream put the data boundary past the end of the record, silently disabling every decoder's boundary check on the three R2010+ fixtures. Those are regenerated. #76 — DICTIONARYVAR / CELLSTYLEMAP are not under-walked. The new examples/probe_reference_closure runs three measurements that never consult the class table, and all three are closed on all 19 files: records tile the section with zero bytes between them; every hard handle reference (§2.13 codes 3 and 5) resolves, the only unanswered references in the corpus being six code-4 soft pointers from BLOCK_HEADER 0xA0B of sample_AC1032.dwg to erased INSERTs; and the AcDbVariableDictionary, sole owner of a drawing's DICTIONARYVAR objects, holds exactly as many keys as the walk finds records on every file — 10/6/5 on the R2004/R2007/R2010 bands that declare 16/11/10, and 5 and 11 on the two files whose class tables agree with the walk. arc_2010.dwg settles CELLSTYLEMAP: it declares one, contains none, and has no ACAD_ROUNDTRIP_2008_TABLESTYLE_CELLSTYLEMAP key for one to hang from. The class parse is not in doubt — arc_2004.dwg's ten records consume 5161 of the declared 5168 bits and eight of ten counts match the walk exactly. The KNOWN_SHORTFALL pins keep their counts (nothing was under-walked to recover) and are re-documented as files that over-declare rather than as an open walker gap; a drop in any walked figure still fails the ratchet. CI gains the closure probe over the canonical fixtures. Closes #76 Closes #77 * docs(changelog): state combined-tree coverage after merging main (3911/525/9 = 88.0%)
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
Two issues, one PR.
#70 — neither reader was on the wrong slot.
BLOCK_RECORDdecoded*D/*T/*Paper_Spacewhere the adjacentBLOCKentity of the same definition decoded*D3/*T9/*Paper_Space0. Both closed their own boundary, so nothing errored — eight BLOCK_HEADERs ofsample_AC1032.dwgsimply came back named*D, which no symbol table can hold. The file itself carries two different strings: the BLOCK_HEADER stores only the stem of an auto-generated name and the numeric suffix lives solely on theBLOCKsentinel.BLOCK_RECORDis the reader that was wrong, and the fix is a join, not a slot change.#56 — the class census is now a CI gate, the 916 unclaimed object-stream bytes are fully explained (they are not padding), and TABLECONTENT / TABLEGEOMETRY is settled as far as this corpus permits.
Evidence — #70
The BLOCK_HEADER string stream genuinely holds the stem
examples/probe_block_names.rs(new) reads both records' string streams positionally, from the bitstring_stream::locatereports, every slot in order.On
arc_2013.dwg, BLOCK_HEADER0x6Cand BLOCK_HEADER0x74are byte-identical apart from their own handle field and their handle streams:Both string streams are
(76, 282)— 206 bits, which the §19.1 trailer declares literally (RS = 0x00CE = 206) — and both parse to exactly["*Paper_Space", "", ""]: a 10-bitBSlength, 192 bits of UTF-16, and two emptyTVslots at 2 bits each. A 13-unit*Paper_Space0needs 222 bits. Reading 16 bits earlier does not parse (theBSat that offset lands on a00control and claims a 340-unit string), so the located start is the only self-consistent one.AutoCAD's own DXF twin says which one is the real name
arc_2013.dxffrom the publicnextgis/dwg_samplesrepository is the same drawing exported by the producer (an Autodesk application —AcDb:AppInfoonsample_AC1032.dwgreads "Trusted DWG last saved by an Autodesk", version 25.0). ItsBLOCK_RECORDtable:6C*Paper_Space*Paper_Space✓*Paper_Space70*Model_Space*Model_Space✓*Model_Space74*Paper_Space0*Paper_Space✗*Paper_Space0✓The sentinel is the authority. On
sample_AC1032.dwgthe stored stem is a prefix of the sentinel name in 27 of 27 definitions and the remainder is decimal digits every time; the 27 sentinel names are distinct where the 27 stored stems collapse to 20 (eight records read*D, three*Paper_Space, three*U, two*T).Not an artefact of the R2007+ string stream
After merging #72,
arc_R14.dwg,arc_2000.dwgandarc_2004.dwgwalk too. They store their names inline — no string stream involved — and show exactly the same disagreement: BLOCK_HEADER0x74reads*Paper_Space, itsBLOCKsentinel0x75reads*Paper_Space0. The split is a property of the record, not of §19.1.The join
tables::block_record::block_sentinel_handle_ofreads theBLOCKhandle out of a BLOCK_HEADER's own handle stream. §20.4.52 puts a NULL reference immediately before it, and that NULL is a hard pointer with a zero-byte counter (code 5,counter 0) — self-identifying, so the scan needs no reactor count and no xdictionary flag:27 of 27 on
sample_AC1032.dwg, 3 of 3 on every R2000-R2018 corpus file, resolving to a record the walker independently classifies asBLOCKin every case.graph::resolve_block_namesperforms the join and is what callers should use for a block table. R13/R14 records carry neither the §19.1 trailer nor theRLobject-data size, so they stay unresolved rather than guessed — pinned as a known limitation byr14_block_names_stay_unresolved_for_want_of_a_handle_stream.The decoder it replaces
The R2007+ BLOCK_HEADER path was the one table entry not on the shared
tables::modern::SplitStreammachinery. It parsed its fields, then — if the resulting position did not read as a "plausible block name" — scanned every bit of the record for the highest-scoring string that looked like one (find_block_name_string_start/block_name_score, scoring*Model_Spaceat 1000,*-prefixed at 600, and so on). That is now gone. The decoder usesopen_table_entry+SplitStream::finish, so a mis-read field is an error instead of a plausible-looking name; all 27 records close on delta 0. Two further fixes fell out: the record'sdescriptionwas read and discarded (now surfaced), and its entry flags used the inlineB, BS, Border rather than the measuredB, B, BS, which hadis_xref_dependentandis_xref_resolvedswapped.Evidence — #56
The census is wired into CI
.github/workflows/ci.yml(coverage-smokejob) runsprobe_class_census --strictover every canonical fixture.--strictdisables the allowlist; the fixtures are self-generated so their census must be exact.tests/canonical_corpus.rs::fixture_class_census_is_exactassertswalked == declared(was>=), with the fixed-type crediting the probe uses.tests/class_census.rs(new) ratchets the real corpus when present: every under-walk that exists today is pinned by file, class and count, so a new one fails and a fixed one also fails, forcing the list to shrink rather than rot.The 916 unclaimed bytes are not padding — the stream is 100 % accounted for
One measured sentence, as asked: the 916 unclaimed bytes are each record's own leading
MChandle-stream-size field, which itsMSobject size does not count — 772 one-byte fields, 70 two-byte fields and a 4-byte section prologue, summing to exactly 916.They are emphatically not alignment padding: only 8 of the 916 bytes are zero. Each inter-record run equals the width of the preceding record's
MCfield in 841 of 841 cases, against 734 of 841 for the "following record" reading — and 100 % onarc_2010.dwg,arc_2013.dwgandline_2013.dwgas well. That settles the open question insrc/string_stream.rs, which noted that "either the record'sMSbyte count excludes theMCfield, or the recorded handle-stream size counts theMCfield itself": it is the first.The probe now reports this as an agreement count rather than a byte total, so a regression surfaces as a disagreement:
TABLECONTENT / TABLEGEOMETRY: not decidable from this corpus
sample_AC1032.dwgdeclares 5 of each against 2ACAD_TABLEentities and contains 2 of each. Three independent measurements place the missing six records outside the drawing:ACAD_TABLEitself declares 2 and walks 2, so the drawing holds exactly two tables, and TABLECONTENT / TABLEGEOMETRY are 1:1 with a table — which cannot yield 2.5 instances each.Against the embedded-sub-record hypothesis:
CELLSTYLEMAP(AcDbCellStyleMap) declares 0 on this file while aTABLESTYLEexists, which is what a class the writer embeds rather than counts looks like — TABLECONTENT declares 5, not 0. Against the stale-counter hypothesis:ACAD_TABLEwould have declared 5 too. Neither survives, and a one-file, two-table corpus cannot separate them. The gate therefore takes an explicit allowlist with that reason (ALLOWLISTinexamples/probe_class_census.rs), tolerating a shortfall on exactly those two classes and never a surplus, and--strictkeeps the question measurable.One thing the census surfaced that is not mine
The R2004, R2007 and R2010 files each under-walk
DICTIONARYVARandCELLSTYLEMAP(e.g.arc_2010.dwg: declared 10 / walked 5, and 1 / 0). This is pre-existing onmain— verified by runningmain's ownprobe_class_censusat3d3d443, which exits 1 with the same numbers. It is an open walker gap, unexplained, and is pinned per file and per count inKNOWN_SHORTFALLso it cannot grow. Follow-up below.Measured results
Merged with
origin/mainat3d3d443before measuring.cargo run --release --example coverage_report -- <19-file corpus>:main3d3d443Unchanged by construction: this PR fixes which name a record reports, not how many records decode. The block-name defect was silent — both readers returned well-formed strings — so no coverage figure ever moved with it, which is exactly why it needed an external oracle to find.
Block names on
sample_AC1032.dwg, before → after:Changes
src/tables/block_record.rs— the R2007+ path moves ontotables::modern::SplitStreamwithfinish()boundary enforcement; the ~110-line name-scoring heuristic (find_block_name_string_start,plausible_tv_at,is_plausible_block_name,block_name_score, a stale copy of the object prefix skipper) is deleted. Newdescriptionandblock_sentinel_handlefields, newblock_sentinel_handle/block_sentinel_handle_at/block_sentinel_handle_of/handle_stream_start. Five new unit tests including a misalignment negative control and three handle-stream anchor cases built from bytes.src/graph.rs— newresolve_block_names.examples/probe_block_names.rs— new; positional dump of both records' string streams plus the resolved join.examples/probe_class_census.rs—--strict, the documentedALLOWLIST, theMCattribution of the unclaimed bytes, and a fix so a file with noAcDb:Classessection is "nothing to census" rather than a parse failure (which is what the canonical fixtures are).tests/block_names.rs— new; 5 tests, corpus-gated.tests/class_census.rs— new; the corpus ratchet.tests/canonical_corpus.rs— the class census is now exact..github/workflows/ci.yml— the census gate.CHANGELOG.md,STATUS.md,CLEANROOM.md.Spec sections
§19.1 (R2007+ string stream), §20.4.52 (BLOCK_HEADER), §2.13 (handle references), §19.4.3 (BLOCK).
Source provenance
Clean-room declaration. All code and tests in this PR were written from scratch. I consulted only sources listed as allowed in
CLEANROOM.md— the freely-redistributable ODA Open Design Specification for .dwg files v5.4.1, the corpus bytes themselves via this repository's probes, and the two public sources disclosed in the newCLEANROOM.mdsection:arc_2013.dxffrom the publicnextgis/dwg_samplesrepository (read only as an oracle, not vendored, contributing no structure or layout), and AutoCAD's anonymous-block naming convention as recalled from Autodesk's public DXF Reference (published documentation, vocabulary only, and independently corroborated by 27 of 27 measured records). I did not consult Autodesk SDK source, ODA SDK source, LibreDWG source, decompilations, or any copyleft-licensed DWG implementation. The§19.5.51citationblock_record.rspreviously carried is withdrawn in favour of§20.4.52.Gate
cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings,cargo test --release(19 suites, 0 failures),cargo deny check all,RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features, andcargo +1.85.0 test --no-runall pass.Follow-ups
DICTIONARYVAR/CELLSTYLEMAPunder-walk on R2004 / R2007 / R2010 (18 pinned entries across 9 files). Pre-existing onmain; the census now makes it visible and bounded. Worth its own issue.arc_R14.dwgstill reports two blocks named*PAPER_SPACE. Pinned by a test that fails the day the R14 handle stream becomes locatable.examples/build_fixtures.rsto emit a BLOCK_HEADER + BLOCK pair would put it in CI;canonical_fixtures_carry_no_block_definitionsfails the moment that happens, so the gate cannot silently stay corpus-only.RawObject::rawmay be one to two bytes short. IfMSexcludes theMCfield, as measured above, the walker'srawslice endsmc_widthbytes early — harmless today because those bytes are the tail of the handle stream, which nothing decodes yet, but it will matter to whoever decodes it. Container-layer work, deliberately not touched here.Closes #70
Closes #56
https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
Note
Medium Risk
Changes core BLOCK_HEADER decoding and public graph APIs (
resolve_block_names); mistakes could mis-name blocks in exports. CI and extensive corpus tests mitigate regression risk.Overview
Fixes #70 by treating BLOCK_HEADER names as stems for auto-generated blocks (
*D,*Paper_Space, etc.) and joining each header to its BLOCK sentinel for the authoritative full name. Addsgraph::resolve_block_names,block_sentinel_handle_of(NULL-handle anchor in §20.4.52), surfacesdescription, and replaces the R2007+ BLOCK_HEADER heuristic name scanner withtables::modern::SplitStreamplus boundary checks. Newprobe_block_namesandtests/block_names.rspin the behavior.Closes #56 by making declared-vs-walked class counts a CI gate:
probe_class_census --stricton canonical fixtures, exact equality incanonical_corpus.rs, andtests/class_census.rsratcheting known shortfalls on the sample corpus. The probe gains an documented ALLOWLIST (TABLECONTENT/TABLEGEOMETRY, DICTIONARYVAR/CELLSTYLEMAP) and reports how unclaimed object-stream bytes map to preceding records’ leading MC fields.Reviewed by Cursor Bugbot for commit 1a565d4. Configure here.