Repository navigation
feat(container): walk objects on R14, R2000 and R2007 — the nine files that reported n/a - #72
Merged
Merged
Conversation
Implements the three container layouts that had no object walk, so `decoded_entities()` returns records on all 19 corpus files instead of 10. R13-R15 (§3.1, §3.2.6): the flat section-locator list already parsed; this names the locators with the canonical `AcDb:` names, reads them as byte ranges, and treats the whole file as the object stream because the object map addresses records by absolute file offset. The §4.4 handle map and the R2000..R2007 `RL` object prologue need no change. R2007 (§5.1-§5.4): new container — Reed-Solomon de-interleave of the 0x400-byte file header, the §5.10 LZ variant, the page map, the section map and per-page data assembly. `src/r21_lz.rs` is new; `src/r2007.rs` replaces the speculative Sec_Mask scaffold, which described a transformation R2007 does not use. Also settles the R2007 half of the split-stream boundary: §19.1's `RL` object-data-size *is* the record's data+string end, which is what `string_stream::data_section_end` now returns for AC1021. Refs #104, #110, #65
`dispatch_fixed_code` was rewritten upstream around `checked_inline`; the LINE arm keeps this branch's version dispatch (§20.4.21 gives R13/R14 two plain `3BD`s where R2000+ use the `RD` + `DD` form). `entity_data_end` and `entity_strings` now answer for R2007 and R13/R14 as well: R2007's boundary is the §19.1 `RL` this branch taught `string_stream` to read, and R13/R14 state the same `RL` inside their common entity data (§20.4.1), which `checked_inline` picks up from the preamble it has just read. So the "returns None on R13/R14/R2007" carve-out is gone — every entity in the corpus now decodes checked.
The R14 / R2000 / R2007 walk put nine files in front of decoders that had only ever seen synthetic streams, and the boundary check the table path now runs turned four wrong field lists into errors instead of plausible numbers. All four were wrong on R2000 and R2004 too. LAYER read a plot flag, a lineweight and a colour after `BS values`; §20.4.54 has `values` (which contains both) and then the colour. LTYPE read an `RC` and an `RS` the spec does not list, pushing every pre-R2007 description three bytes late. BLOCK_HEADER stopped 12 bits early, missing the R2000+ insert-count run, description and preview blob. DIMSTYLE read 15 of ~70 fields and could not close at all. All four now land on delta 0, and the same drawing decodes to the same values from R14 through R2018 — layer `0` colour 7, `*Active` view height 288.065353, `ISO-25` at the published ISO defaults, `Continuous` described as `Solid line`. Adds an R2000 canonical fixture built through the §3.2.6 flat assembler, eleven byte-built container tests, and two probes. Closes #104, #110, #65 Refs #21, #103
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_ce0b2aa8-24ce-428e-80e4-3894c0f08f06) |
This was referenced Aug 30, 2026
DrunkOnJava
added a commit
that referenced
this pull request
Aug 30, 2026
… list, four releases (#79) #72 made the R14 / R2000 / R2007 object walk work and their 216 VISUALSTYLE records reached a decoder for the first time. Neither shipped list closed on any of them, and #73 opened on the obvious reading: a third generation of the layout. There is not one. Measured first, the corpus: every one of the nineteen files holds exactly 24 VISUALSTYLE records, R14 included, so the 216 split 72 / 72 / 72 rather than 108 / 108 / 0. R14 and R2000 write the same 30 flag-less fields in the same order as R2004. The whole difference is §2.11 — before R2004 a colour is the bare BS index, without the BL true-colour word and RC colour byte. Read the five colour slots that way and the list lands all 144 records of the six R14 / R2000 files exactly on their boundary, delta 0. The two encodings agree through the change: R2004's "none" 0xC8000000 is index 257, 0xC3000007 is index 7, and ColorChange's grey 0xC2808080 (face + edge) and Shaded's 0xC2787878 silhouette are ACI index 8 — in exactly those three slots of exactly those two records. R2007 keeps the R2004 colour form and adds exactly one 2-bit slot before the record's final B. With the R2004 list its records land two bits short on all 72, and the leftover bits are 10 then is_internal_use_only — 101 on the fourteen hidden styles, 100 on the ten listed ones, on every record of all three files. Dim pins the position: it is the one record whose display_brightness is the full 34-bit BL rather than the 2-bit zero form, and placing the slot before the brightness closes 23 of 24 and fails on exactly Dim. The head and after-the-final-B placements fail on all 24. Declined honestly: the new slot's token type and its side of display_shadow_type are not determined — both are two bits reading 0 on all 72 records — so it is surfaced as display_unknown_short rather than named after a guess. It is not R2010's format_version, which decodes 2. examples/probe_visualstyle_layout.rs is new: census, joint-boundary check and one-token uniqueness search over every VISUALSTYLE record of every file named. Its --search mode reports 33 closing neighbours on R2007 and 64 on R14 / R2000, all encoding aliases rather than rival layouts — pre-R2004 a colour is a BS, and BS / BL / BD coincide on the small-value forms these records use. Width alone does not pick the layout; the cross-release value agreement does. Measured on the 19-file corpus (examples/coverage_report.rs), merged onto origin/main at 6cc9b13: R14 426 / 450 / 0 / 48.6 % -> 498 / 378 / 0 / 56.8 % R2000 534 / 99 / 0 / 84.4 % -> 606 / 27 / 0 / 95.7 % R2007 462 / 96 / 0 / 82.8 % -> 534 / 24 / 0 / 95.7 % TOTAL 3695 / 741 / 9 / 83.1 % -> 3911 / 525 / 9 / 88.0 % VISUALSTYLE leaves the unhandled histogram entirely; XRECORD (345) is now the largest unmatched class, and the error count is unchanged. Closes #73 Claude-Session: https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
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.
Nine of the nineteen corpus files reported
n/a (no-handle-map)inevery coverage table this project has ever published. Not "decoded
badly" — not walked at all. Three whole release bands, and with them
the pre-2004 half of every field list in the crate, had no evidence
behind them.
They all decode now, with zero errored records.
Per-file coverage, all 19 files
examples/coverage_report.rs ../../samples, on this branch merged withorigin/main@ e10cb79:arc_R14.dwgcircle_R14.dwgline_R14.dwgarc_2000.dwgcircle_2000.dwgline_2000.dwgarc_2004.dwgcircle_2004.dwgline_2004.dwgarc_2007.dwgcircle_2007.dwgline_2007.dwgarc_2010.dwgcircle_2010.dwgline_2010.dwgarc_2013.dwgcircle_2013.dwgline_2013.dwgsample_AC1032.dwgBaseline on
origin/mainwas 2273 / 96 / 9 / 95.6 % over the tenfiles that were walkable, with the other nine printing
n/a.The aggregate ratio fell because the corpus it averages over grew by
nine files, not because anything decodes worse. The ten previously
walkable files are byte-identical in outcome. The nine new ones
contribute 1422 decoded records and 0 errors — and 645 skipped ones,
because VISUALSTYLE, XRECORD and MATERIAL are as unmatched there as
everywhere else. Comparing 83.1 % to 95.6 % compares two different
corpora; the per-version rows are the numbers that mean something.
The nine errors are
origin/main's pre-existing, named VIEWPORT (6),MESH (2) and LEADER (1) residues on
sample_AC1032.dwg— untouched bythis branch. Handle-map self-check: 0 mismatches across all 19 files.
Walker diagnostics: every handle-map entry resolved to a record.
What landed, per band
R13-R15 (
AC1014,AC1015) — the file is the object stream§3.2.6 gives these releases a flat list of
(record number, absolute seeker, size)locators instead of a page map, and §3.1 puts the objectrecords loose in the file. There is no
AcDb:AcDbObjectssection: theobject map's offsets are absolute file offsets.
So this needed no new container machinery.
DwgFile::object_stream()hands back the whole file, the §4.4 handle-map parser runs unchanged on
the locator's byte range, and
ObjectWalker::with_handle_mapseeks toeach offset as it does on R2018. The locators are given the canonical
AcDb:names sohandle_map(),class_map()andheader_vars()stayversion-agnostic one level up.
Evidence. Every record repeats its own handle. All 292 entries per
R14 file and all 211 per R2000 file land on a record whose handle field
matches the map — 1509 of 1509 across the six files, zero mismatches,
zero skips.
Two further R13/R14 findings, both in the spec and both measured:
RLobject-data-size twice, under"R2000+" (in the object prologue) and under "R13-R14" (after the EED
chain, or after the graphics-present flag for an entity). The walker
settles the first half by construction — it reads the handle straight
after the type code and 876/876 handles then match.
examples/probe_r13_r14_prefix.rssettles the second: all 285 non-entity records per R14 file carry a
value there that is
> 0, no larger than the payload, and past thecursor; 135 then have a field list that closes on it exactly. That
field is R14's data-stream boundary.
3BDs where R2000+ use theZ's are zero+RD/DDform. Under the R2000+ reading the LINErecord of every R14 file runs off the end of its payload; under the
R13/R14 one it decodes to
(50, 50, 0) -> (100, 100, 0)— the sameauthored geometry
line_2013.dwgalready asserts.R2007 (
AC1021) — §5.1-§5.4, and not one mechanism from §4src/r2007.rspreviously described R2007 as "two-layer Sec_Mask": abyte XOR against a rolling LCG plus a bit rotation over 7-byte windows.
R2007 uses neither. That module described a transformation the
format does not have, so it is replaced rather than kept as a scaffold
(
xor_layer_1androtate_layer_2are removed from the public API).What §5 actually specifies:
Sec_Mask-XOR'd header per pagefactortimesencoding == 4New:
src/r21_lz.rs(the §5.10 decompressor) and a rewrittensrc/r2007.rs(file header, page map, section map, per-page assembly).A valid file needs no error correction, only the interleaving, so
deinterleavegathers each codeword's message bytes andcrate::reed_solomonstays the repair path.Two byte-level findings this took:
The §5.10 literal copy is a permutation, applied recursively.
The spec prints a table of "sub byte blocks" per copy length and one
sentence — "the order of bytes in source and target buffer are
different" — that reads like an implementation note about a
hand-optimised
memcpy. It is not: the blocks are the smaller copyfunctions themselves, so a 2-byte block comes out reversed and a
16-byte block comes out with its halves swapped.
00 700x70000x70, the value §5.2 namesAcDb:Ap\0pInfoHistory— invalid UTF-16AcDb:AppInfoHistoryThe Reed-Solomon block count for a system page is
ceil(factor · align8(stored) / 239), read backwards out of §5.3'sconstruction.
page_size / 255gives the same answer for the pagemap and a different one for the section map (15 blocks in an
18-block-wide page), so only the section map exposes it.
Evidence.
examples/probe_r2007_container.rsprints every constant§5.2 documents with a pass/fail verdict. On all three AC1021 corpus
files: header size
0x70✓, the "normally" fields0x20/0x40/0xf800/4/1✓,StreamVersion 0x60100✓, andFile sizeequal to the file's own byte count (66304 / 66304 / 66560) ✓. The
section map then yields thirteen sections whose hash codes match the
§5.2 table for all twelve the table lists; the thirteenth is
AcDb:AppInfoHistory, which AutoCAD writes and ODA does not. Theassembled sections open with the structures they must:
AcDb:Classeswith the §21 sentinel,
AcDb:AcDbObjectswith theRL0x0dca,AcDb:Handleswith a big-endian section size that fits.SectionMapStatus::Deferredis gone for AC1021.#65 — R2007's split-stream boundary
R2010+ locate the §19.1 string-stream trailer from the leading
MChandle-stream size. R2007 has no
MC— and its §19.1RLobject-data-size is the data-and-string end, i.e. exactly the
endbitthe trailer prose is written around.Running the trailer backwards from it yields a string stream whose
first
TUis the record's own name on every named record of everyR2007 file:
0,Standard,ACAD,*Active,ISO-25,Annotative,ByBlock,ByLayer,Continuous,AcadAnnotative,*Model_Space,*Paper_Space,ACAD_NAV_VCDISPLAY. That one arm instring_stream::data_section_endis what lets the entiretables::modern/objects::modernfamily run on AC1021 without aline of new decoder code — the R2007 declines across every decoder.
Every entity, every release, boundary-checked
entities::dispatch::checked_inline(from #69) returnedNonefor theboundary on R13/R14 and R2007. Both bands state one — R2007 through the
trailer above, R13/R14 through the
RL§20.4.1 places inside the commonentity data — so the carve-out is gone. The pre-R2007 symbol-table
path is now checked too, which it never was. No entity or table entry
in the corpus decodes unchecked on any release.
Four pre-R2007 field lists the new files exposed
Turning the check on put four decoders that had only ever seen
synthetic streams in front of real records. Each was wrong — and each
was wrong on R2000 and R2004 as well; only files that reach a decoder
could show it. All four now close on delta 0:
BS values,B plot,BS lineweight,BS colourBS values— which contains plot and lineweight — thenCMCline_2004.dwgreported lineweight −32765, colour −31231RC flags+RS used_countbefore the descriptionlid lineforSolid lineon every pre-R2007 fileTV, a preview blobAlso fixed for R14 specifically: the §20.1
RLafter the EED chain(which every DICTIONARY / APPID / LTYPE / DIMSTYLE / BLOCK_HEADER record
needed), DICTIONARY's single
RCwhere R2000+ writeBS+RC(§20.4.44), DICTIONARYWDFLT's extra
TV(§20.4.45),DIMSTYLE_CONTROL's absent trailing
RC, VPORT's absent render mode andper-viewport UCS block (§20.4.64), and the
BBlinetype/plot-styleflags that are R2000+ only.
The corroboration is cross-version. The same drawing exists in
seven releases, so its values must agree. They now do:
0colour*Activeview heightISO-25dimscale / dimasz / dimexoContinuousdescriptionSolid lineSolid lineSolid lineSolid lineSolid line(The R14 DIMSTYLE cell is empty on purpose — see below.)
Tests, fixtures, probes
tests/integration_legacy_container.rs— 11 tests. Seven arebyte-built: complete R14 and R2000 flat files assembled by
BitWriter(locator table, object record with a computedRL,handle map) and walked end to end to a LINE with asserted geometry;
an R2007 payload whose string stream is located from its
RL; the§5.3.1 page-size pseudo-code; the §5.2 page-map accumulation loop.
Four are corpus-gated and skip when
samples/is absent.examples/build_fixtures.rsnow emitssynthetic_2000.dwgthrough a flat §3.2.6 assembler — the R2000 half of No canonical fixture (and therefore no coverage gate) for R14 / R2000 / R2007 — assemble_dwg_bytes rejects those versions #21. The
committed corpus is 5 files / 25 entities / 100 %, and the new
one is the only fixture whose handle-map offsets are file offsets
rather than section offsets, so it gates a genuinely different code
path.
tests/canonical_corpus.rspins it.examples/probe_r2007_container.rsandexamples/probe_r13_r14_prefix.rsprint the evidence above.src/r21_lz.rspin each permutation width and thedocumented header prefix;
src/r2007.rspins the page size,de-interleave, page map, section-map name length and the
encrypted-section refusal.
Lib tests 751 → 766; integration suites all green.
What stayed blocked, and why
single entry in the unhandled column. With the walk open, the
R2004 flag-less list (feat(objects): decode VISUALSTYLE on R2004 — the flag-less generation (72 records, 92.0% → 95.0%) #64) could finally be tried against them: all
216 miss their data-stream boundary. That is 216 records of evidence
that a third layout exists and none about what it is, so the module
keeps returning
Unsupportedfor those releases. The negative resultis recorded in
objects/acad_visual_style.rs.block — flags first as
Bs andRCs, then theBDvariables, in anorder that shares nothing with the R2000+ list. Reported unhandled
rather than decoded from an unmeasured order. The R2000+ inline list
itself is now complete.
encryption is refused with
Error::Unsupported, not decoded.need a Reed-Solomon encoder and a §5.10 compressor; the R14 half of
No canonical fixture (and therefore no coverage gate) for R14 / R2000 / R2007 — assemble_dwg_bytes rejects those versions #21 needs
ElementEncoderto emit the §20.4.1 R13/R14 preamble.unmatched everywhere, not a property of the new bands.
Incidental
wasm/Cargo.lockpicks upthiserror2.x, which the parent cratealready depends on; running the wasm test suite regenerates it either
way.
Clean-room declaration
I certify that:
CLEANROOM.md— thefreely-redistributable ODA Open Design Specification for .dwg
files v5.4.1 (§3.1, §3.2.6, §5.1-§5.4, §5.10, §5.13, §19.1, §20.1,
§20.4.1/.21/.44/.45/.52/.54/.58/.64/.68) and first-party byte
inspection of publicly-available DWG files. 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.
readings that are measured rather than prescribed — the
recursive sub-block table, the system-page block count, the
byte-counted
SectionNameLength, and DICTIONARYWDFLT's extraTVon R14 — are each labelled as such at the module that owns them and
summarised in the new
CLEANROOM.mdentry.commercial or NDA'd context.
Closes #104
Closes #110
Closes #65
Refs #21, #103
https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
Note
High Risk
Rewrites core container parsing for three release bands and changes many symbol-table/entity field layouts (including R2000/R2004); regressions would mis-read DWG bytes, though boundary checks and expanded tests reduce that risk.
Overview
Enables handle-map object walking on the nine corpus files that previously returned
n/a (no-handle-map)— R14/R2000 via §3.2.6 flat locators (whole-file object stream, absolute offsets, canonicalAcDb:section names) and R2007 via a full replacement of the old incorrect Sec_Mask scaffold.R2007 (
src/r2007.rs, newsrc/r21_lz.rs) implements the real §5.1–§5.4 stack: Reed-Solomon de-interleaving, page/section maps, per-section assembly, and §5.10 LZ with recursive literal-byte permutation (not R2004 LZ77). Publicxor_layer_1/rotate_layer_2are removed. Password-protected sections are refused.#65:
string_streamlocates R2007 split-stream boundaries from §19.1RL, so existingtables::modern/objects::moderndecoders run on AC1021 without new per-type code. Entity dispatch now uses R2007+ string streams and boundary checks on every release (R14RLafter graphics/EED, inline table entries checked too).Decoder/layout fixes exposed once real pre-2004 records were visible — LAYER, LTYPE, BLOCK_HEADER, DIMSTYLE (R2000+ inline), R14 LINE
3BDbodies, DICTIONARY/DICTIONARYWDFLT/DIMSTYLE_CONTROL/VPORT/class-map bit offsets, and related R14 object-prefix reads.synthetic_2000.dwgand integration probes document the measurements.Docs/README coverage tables move from “not supported” to per-version decode rates (aggregate 83.1% over 19 files vs 95.6% over 10). VISUALSTYLE on R14/R2000/R2007 and R14 DIMSTYLE remain explicitly unhandled.
Reviewed by Cursor Bugbot for commit e0823f2. Configure here.