Skip to content

feat(container): walk objects on R14, R2000 and R2007 — the nine files that reported n/a - #72

Merged
DrunkOnJava merged 3 commits into
mainfrom
feat/r14-r2000-r2007-object-walk
Aug 30, 2026
Merged

DrunkOnJava merged 3 commits into
mainfrom
feat/r14-r2000-r2007-object-walk

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Nine of the nineteen corpus files reported n/a (no-handle-map) in
every 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 with
origin/main @ e10cb79:

file version decoded skipped errored walker skips ratio
arc_R14.dwg AC1014 142 150 0 0 48.6 %
circle_R14.dwg AC1014 142 150 0 0 48.6 %
line_R14.dwg AC1014 142 150 0 0 48.6 %
arc_2000.dwg AC1015 178 33 0 0 84.4 %
circle_2000.dwg AC1015 178 33 0 0 84.4 %
line_2000.dwg AC1015 178 33 0 0 84.4 %
arc_2004.dwg AC1018 194 5 0 0 97.5 %
circle_2004.dwg AC1018 194 5 0 0 97.5 %
line_2004.dwg AC1018 194 5 0 0 97.5 %
arc_2007.dwg AC1021 154 32 0 0 82.8 %
circle_2007.dwg AC1021 154 32 0 0 82.8 %
line_2007.dwg AC1021 154 32 0 0 82.8 %
arc_2010.dwg AC1024 177 4 0 0 97.8 %
circle_2010.dwg AC1024 177 4 0 0 97.8 %
line_2010.dwg AC1024 177 4 0 0 97.8 %
arc_2013.dwg AC1027 128 4 0 0 97.0 %
circle_2013.dwg AC1027 128 4 0 0 97.0 %
line_2013.dwg AC1027 128 4 0 0 97.0 %
sample_AC1032.dwg AC1032 776 57 9 0 92.2 %
TOTAL 3695 741 9 0 83.1 %

Baseline on origin/main was 2273 / 96 / 9 / 95.6 % over the ten
files 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 by
this 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 object
records loose in the file. There is no AcDb:AcDbObjects section: the
object 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_map seeks to
each offset as it does on R2018. The locators are given the canonical
AcDb: names so handle_map(), class_map() and header_vars() stay
version-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:

  • §20.1 / §20.4.1 list the RL object-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.rs
    settles the second: all 285 non-entity records per R14 file carry a
    value there that is > 0, no larger than the payload, and past the
    cursor; 135 then have a field list that closes on it exactly. That
    field is R14's data-stream boundary.
  • §20.4.21 gives R13/R14 two plain 3BDs where R2000+ use the
    Z's are zero + RD/DD form. Under the R2000+ reading the LINE
    record 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 same
    authored geometry line_2013.dwg already asserts.

R2007 (AC1021) — §5.1-§5.4, and not one mechanism from §4

src/r2007.rs previously described R2007 as "two-layer Sec_Mask": a
byte 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_1 and rotate_layer_2 are removed from the public API).

What §5 actually specifies:

layer R2004 / R2010+ R2007
file header 0x6C bytes at 0x80, XOR against the magic sequence 0x400 bytes at 0x80, Reed-Solomon (255, 239) + §5.10 LZ
page header 32-byte Sec_Mask-XOR'd header per page none — pages are bare
compression LZ77 §4.7 a different LZ variant, §5.10
system pages plain RS (255, 239) interleaved, data repeated factor times
data pages plain RS (255, 251) interleaved when encoding == 4

New: src/r21_lz.rs (the §5.10 decompressor) and a rewritten
src/r2007.rs (file header, page map, section map, per-page assembly).
A valid file needs no error correction, only the interleaving, so
deinterleave gathers each codeword's message bytes and
crate::reed_solomon stays the repair path.

Two byte-level findings this took:

  1. 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 copy
    functions themselves, so a 2-byte block comes out reversed and a
    16-byte block comes out with its halves swapped.

    where source bytes straight copy recursive copy
    file header, first literal 00 70 header size 0x7000 header size 0x70, the value §5.2 names
    section map, an 11-byte literal inside a section name AcDb:Ap\0pInfoHistory — invalid UTF-16 AcDb:AppInfoHistory
  2. The Reed-Solomon block count for a system page is
    ceil(factor · align8(stored) / 239)
    , read backwards out of §5.3's
    construction. page_size / 255 gives the same answer for the page
    map 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.rs prints every constant
§5.2 documents with a pass/fail verdict. On all three AC1021 corpus
files: header size 0x70 ✓, the "normally" fields 0x20 / 0x40 /
0xf800 / 4 / 1 ✓, StreamVersion 0x60100 ✓, and File size
equal 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. The
assembled sections open with the structures they must: AcDb:Classes
with the §21 sentinel, AcDb:AcDbObjects with the RL 0x0dca,
AcDb:Handles with a big-endian section size that fits.
SectionMapStatus::Deferred is gone for AC1021.

#65 — R2007's split-stream boundary

R2010+ locate the §19.1 string-stream trailer from the leading MC
handle-stream size. R2007 has no MC — and its §19.1 RL
object-data-size is the data-and-string end, i.e. exactly the
endbit the trailer prose is written around.

Running the trailer backwards from it yields a string stream whose
first TU is the record's own name on every named record of every
R2007 file: 0, Standard, ACAD, *Active, ISO-25, Annotative,
ByBlock, ByLayer, Continuous, AcadAnnotative, *Model_Space,
*Paper_Space, ACAD_NAV_VCDISPLAY. That one arm in
string_stream::data_section_end is what lets the entire
tables::modern / objects::modern family run on AC1021 without a
line of new decoder code — the R2007 declines across every decoder.

Every entity, every release, boundary-checked

entities::dispatch::checked_inline (from #69) returned None for the
boundary 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 common
entity 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:

decoder was §20.4.x says delta before
LAYER BS values, B plot, BS lineweight, BS colour BS values — which contains plot and lineweight — then CMC overshoot; line_2004.dwg reported lineweight −32765, colour −31231
LTYPE RC flags + RS used_count before the description neither field exists description three bytes late — lid line for Solid line on every pre-R2007 file
BLOCK_HEADER stopped after the xref path R2000+ add an insert-count run, a description TV, a preview blob −12 bits on all six R2000/R2004 records
DIMSTYLE 15 of ~70 fields the whole §20.4.68 R2000+ body −298 to −440 bits

Also fixed for R14 specifically: the §20.1 RL after the EED chain
(which every DICTIONARY / APPID / LTYPE / DIMSTYLE / BLOCK_HEADER record
needed), DICTIONARY's single RC where R2000+ write BS + RC
(§20.4.44), DICTIONARYWDFLT's extra TV (§20.4.45),
DIMSTYLE_CONTROL's absent trailing RC, VPORT's absent render mode and
per-viewport UCS block (§20.4.64), and the BB linetype/plot-style
flags that are R2000+ only.

The corroboration is cross-version. The same drawing exists in
seven releases, so its values must agree. They now do:

record R14 R2000 R2004 R2007 R2013
LAYER 0 colour 7 7 7 7 7
VPORT *Active view height 288.065353 288.065353 288.065353 288.065353 288.065353
DIMSTYLE ISO-25 dimscale / dimasz / dimexo — 1.0 / 2.5 / 0.625 1.0 / 2.5 / 0.625 1.0 / 2.5 / 0.625 1.0 / 2.5 / 0.625
LTYPE Continuous description Solid line Solid line Solid line Solid line Solid line
LINE geometry (50,50,0)→(100,100,0) same same same same

(The R14 DIMSTYLE cell is empty on purpose — see below.)

Tests, fixtures, probes

  • tests/integration_legacy_container.rs — 11 tests. Seven are
    byte-built: complete R14 and R2000 flat files assembled by
    BitWriter (locator table, object record with a computed RL,
    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.rs now emits synthetic_2000.dwg
    through 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.rs pins it.
  • examples/probe_r2007_container.rs and
    examples/probe_r13_r14_prefix.rs print the evidence above.
  • Unit tests in src/r21_lz.rs pin each permutation width and the
    documented header prefix; src/r2007.rs pins 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

  • VISUALSTYLE on R14 / R2000 / R2007 — 216 records, the largest
    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 Unsupported for those releases. The negative result
    is recorded in objects/acad_visual_style.rs.
  • DIMSTYLE on R14 (6 records). §20.4.68 gives R13/R14 their own
    block — flags first as Bs and RCs, then the BD variables, in an
    order that shares nothing with the R2000+ list. Reported unhandled
    rather than decoded from an unmeasured order. The R2000+ inline list
    itself is now complete.
  • Password-protected R2007 files. A section descriptor declaring
    encryption is refused with Error::Unsupported, not decoded.
  • Writing R14 or R2007. Both containers are read-only. R2007 would
    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 ElementEncoder to emit the §20.4.1 R13/R14 preamble.
  • XRECORD (345), MATERIAL (65), TABLESTYLE (19) are unchanged —
    unmatched everywhere, not a property of the new bands.

Incidental

wasm/Cargo.lock picks up thiserror 2.x, which the parent crate
already depends on; running the wasm test suite regenerates it either
way.

Clean-room declaration

I certify that:

  1. All code and tests in this PR were written from scratch by me.
  2. I consulted only sources listed as allowed in CLEANROOM.md — the
    freely-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.
  3. Every citation is in the diff as a comment or doc link, and the four
    readings that are measured rather than prescribed — the
    recursive sub-block table, the system-page block count, the
    byte-counted SectionNameLength, and DICTIONARYWDFLT's extra TV
    on R14 — are each labelled as such at the module that owns them and
    summarised in the new CLEANROOM.md entry.
  4. I have never had access to any of the forbidden sources in a
    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, canonical AcDb: section names) and R2007 via a full replacement of the old incorrect Sec_Mask scaffold.

R2007 (src/r2007.rs, new src/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). Public xor_layer_1 / rotate_layer_2 are removed. Password-protected sections are refused.

#65: string_stream locates R2007 split-stream boundaries from §19.1 RL, so existing tables::modern / objects::modern decoders run on AC1021 without new per-type code. Entity dispatch now uses R2007+ string streams and boundary checks on every release (R14 RL after 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 3BD bodies, DICTIONARY/DICTIONARYWDFLT/DIMSTYLE_CONTROL/VPORT/class-map bit offsets, and related R14 object-prefix reads. synthetic_2000.dwg and 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.

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
@cursor

cursor Bot commented Aug 30, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@DrunkOnJava
DrunkOnJava merged commit 3d3d443 into main Aug 30, 2026
20 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/r14-r2000-r2007-object-walk branch August 30, 2026 22:28
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

string_stream::data_section_end has no R2007 path — a separate blocker from #110 for every R2007 split-stream decode

1 participant