Skip to content

feat(container): open and walk AC1012 (R13), pinned on 22 real drawings (#119) - #323

Open
DrunkOnJava wants to merge 27 commits into
mainfrom
feat/r13-reader
Open

DrunkOnJava wants to merge 27 commits into
mainfrom
feat/r13-reader

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

DwgFile opens and walks AC1012 (R13): 22 real R13 drawings are pinned in the corpus, every handle-map entry of all of them lands on a record that repeats its handle, and the R13-R14 fixes the new files surfaced are in (#119).

Spec reference

ODA v5.4.1 §3, §9, §10.1, §14.2, §20.1, §20.4.1, §20.4.44, §23.1, §26 and §2.8/§2.10. The findings, with bit evidence, are ARCHITECTURE.md §7au and the notes of docs/data/spec-coverage.tsv. R13 claims boundaries only: no AutoCAD DXF of an R13 drawing exists, so no row changes state and nothing is marked complete.

What the PR contains, one commit each:

  1. tools/corpus/pins.tsv: SketchUp's Cabin.dwg (Apache-2.0) and the 21 Sovol3d/SOVOL-ZERO drawings (no licence stated: fetched by pinned hash, never committed). fetch.py now percent-encodes the repository path: the Sovol paths are Chinese part names with spaces, and the unquoted URL raises http.client.InvalidURL, which fetch.py does not catch. CLEANROOM.md records the provenance.
  2. Version::R13 (AC1012) and Version::is_r13_r14(); every "is R14" test the crate wrote for an R13-R14 branch now asks it.
  3. Streaming grammar: main fixed the object-map chunk bound (2034, not 2032) while this PR was open (§7ac); this PR keeps what it added on top: tools/streaming/verify_walk.py also walks Cabin.dwg and two Sovol drawings (manifests walk-sketchup-corpus.json, walk-sovol-corpus.json) and percent-encodes their URLs.
  4. read_bt_for / read_be_for: BT and BE on R13-R14 are a bare BD and 3BD (§2.8, §2.10).
  5. DICTIONARY's unknown byte is R14 only (§20.4.44).
  6. Two probes: examples/probe_r13_container.rs and examples/probe_r13_entities.rs.
  7. header_vars.rs matched Version exhaustively, so it gets an R13 arm (the table already carries the R13 rows); an AC1012 header whose R13 rows leave a whole byte is read with the R14 rows (see the header bullet below); the R13-R14 branches of MTEXT (fix(entities): read MTEXT's §20.4.46 version branches on R13 to R2004 (#226) #261) and LWPOLYLINE (fix(entities): route the R14 LWPOLYLINE and HATCH classes and read LWPOLYLINE's R13-R14 vertices (#229) #264), written as == Version::R14, ask is_r13_r14().
  8. tools/corpus/baseline.tsv: 22 added rows, no existing row changed.
  9. ARCHITECTURE.md §7au, spec-coverage notes, the lib.rs version table, README, ROADMAP's containers row.
  10. examples/probe_dxf_header.rs (feat(dxf): write the decoded header into dwg-to-dxf's HEADER section (#126) #320) matched Version exhaustively, so clippy --all-targets failed on the merged tree once Version::R13 existed; R13 maps to no DXF header writer, as R14.

Evidence

Before: every one of the 22 files is open-failed: Unsupported DWG version. After (coverage_report, with main at 4ec356a, which brings #258, #297 and #249, merged in):

source records decoded skipped errored
Cabin.dwg 3,590 3,353 0 237
Sovol, 21 drawings 24,124 23,901 21 202
  • Handle map: 27,714 of 27,714 entries resolve on a record whose own handle repeats it; 0 mismatches, 0 walk skips; 0 bytes between records (probe_reference_closure); every class reaches its declared count (probe_class_census).
  • Container: probe_r13_container re-reads the framing independently and passes locator CRC, sentinels, image sentinel, §9 and §10.1 sections and every §23.1 chunk CRC on all 22. Two layouts: Cabin.dwg has 4 locators (CRC XOR 0x8101, first count-4 file measured) with image data at the end; the Sovol drawings have 5 (0x3CC4) with image data at 0x58. No three-locator (C2) drawing exists in the corpus.
  • Streaming: stream_walk and stream_walk --legacy list the same records on all 22 and on ACadSharp's sample_AC1014.dwg and sample_AC1015.dwg. Before main's chunk fix (§7ac) 9 of those 24 (7 R13, the R14 and the R2000) failed with MapChunk; their chunks are 2033 or 2034 bytes (the size field counts its own two bytes, so §23.1's 2032 counts the entries). tools/streaming/verify_walk.py now also walks Cabin.dwg and two Sovol drawings (beside main's ACadSharp files) against its independent framing parse.
  • BT/BE: LINE 0x28 of Cabin.dwg (RL boundary 605): read as BD + 3BD it ends on bit 605 with thickness 1.0 and extrusion (-1, -3e-16, 0); read as BT + BE it reads a reserved 11 BD tag. 18 LINE and 2 POLYLINE_2D records close that errored; no R14 or R2000 baseline row moves (their records have the default thickness and extrusion, for which the two forms read the same bits).
  • DICTIONARY: 88 R13 records missed their boundary (by 8 bits when empty); all close.
  • MTEXT: all 3,968 R13 MTEXT records of the Sovol drawings closed only after item 7.
  • Header variables (§9): all 22 decode strictly to the stated size (the Corpus job's probe_header_vars runs on them and exits 0). Cabin.dwg closes on the 195 R13 slots. The 21 Sovol headers read their R13 slots plausibly and then hold 84 bits: four BS 00 + FFFF (72 bits) and 12 bits of padding. The four BS are §9's "R14+" block, "unknown short (type 5/6 only) ... these do not seem to be required" (the Sovol writer writes -1 in each; AutoCAD's R14 files hold arbitrary values). The 12 bits are the 4 bits ending the byte of the last slot (1010 in all 21) and one whole byte more (00 in 19, 52 and 7F in the others): the Sovol section size is ceil(bits/8)+1 (403 to 404 bytes, 395 to 396). The padding bits do not tell writers apart (Autodesk's own R13 discs pad 0000 in 196 of 263 headers and 1111 in 6, R13: no AutoCAD-written AC1012 drawing in the public corpus #345); what holds on every AutoCAD-written R13 header is 195 slots in a section of exactly ceil(bits/8), so the Sovol files are non-AutoCAD on the extra byte, a blank preview bitmap (the same 180 x 97 image in all 21) and the R2007+ SUN object. An AC1012 header whose R13 rows leave a whole byte is therefore read with the R14 rows and may end one byte before its data does; that tolerance is for this writer's variant, confined to AC1012, not AutoCAD's format. Cabin.dwg and every other release read as before. Bit evidence in ARCHITECTURE.md §7au.
  • The remaining 439 errors are all in decoders that main added after the R13 branch started and that test == Version::R14 or matches!(version, Version::R14): ATTRIB 179 and ATTDEF 57 (TEXT family, fix(entities): read TEXT, ATTRIB and ATTDEF as §20.4.3-§20.4.5 print them on every release (#226, #62) #258), DIMSTYLE 161 (fix(tables): decode R14 DIMSTYLE with §20.4.68's R13/R14 block (#74) #297), LEADER 42 (fix(entities): read §20.4.47 LEADER's end point projection and tails on every release (#71) #249). The 21 skipped are one SUN class record per Sovol drawing. The follow-up that swaps those tests for is_r13_r14() (and skips LEADER's Endptproj on R13, which §20.4.47 marks "R14+") is a separate PR with its own R13 and R14 corpus evidence; in a scratch tree with those swaps Cabin.dwg was 3,590 decoded, 0 skipped, 0 errored and the 21 Sovol drawings 24,103 decoded, 21 skipped (SUN), 0 errored. Every other release stays at 0 errors.

Reproduce (the commands the Corpus job runs):

python3 -I tools/corpus/fetch.py --dest ../dwg-corpus
cargo build --release --features dxf-reader --example coverage_report \
    --example probe_class_census --example probe_reference_closure \
    --example probe_r13_container --example probe_r13_entities
python3 -I tools/corpus/measure.py run --corpus ../dwg-corpus --bin target/release/examples --out r.json
python3 -I tools/corpus/measure.py check --results r.json
target/release/examples/probe_r13_container ../dwg-corpus/sketchup/Cabin.dwg ../dwg-corpus/sovol/*.dwg

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features, cargo +1.85 check --all-features
  • cargo test --release --all-features --no-fail-fast: no unit test added. One existing test encoded the disproven behaviour and is adapted: tests/integration_legacy_container.rs write_r13_r14_line_body wrote the R14 LINE's thickness and extrusion as the two one-bit R2000+ defaults; it writes the bare BD and 3BD that §2.8 and §2.10 print.
  • Shown on real files: the 74-drawing corpus run above (measure.py check differs from the committed baseline only by the 22 added rows), the dxf_oracle ratchet, probe_r2007_rs, probe_data_page_header --strict and probe_header_vars (exit 0, all 22 R13 headers closed) with the R13 files in the directory, tools/streaming/verify_walk.py against a release build (CI runs the debug one).

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF (sha256 973628f3...504b) is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, or any copy of its example files) was consulted or imported.

My contribution is based on the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1) and on byte-level inspection of the 22 public drawings pinned in tools/corpus/pins.tsv, read only through this crate and its probes (no code from SketchUp/sketchup-developer-tools or Sovol3d/SOVOL-ZERO was consulted). No reading of another DWG implementation's comments was needed; nothing needs adding to CLEANROOM.md beyond the corpus provenance entry in this PR.

Developer Certificate of Origin

I affirm that the contribution complies with the Developer Certificate of Origin 1.1.

… R13-R15 container (#119)

R13 shares the flat section-locator container, the unframed object stream
and the R13-R14 branches of the entity and object prologues with R14, so
every test the crate wrote as 'is R14' for one of those branches becomes
is_r13_r14().
…es, so its size field reaches 2034 (#213)

The walk refused any chunk whose size field passed 2032. That rejected 7
of 22 real R13 drawings and the AutoCAD-saved R14 and R2000 drawings of
ACadSharp, which hold chunks of 2033 and 2034 bytes. The streaming E2E
now walks one of each against an independent framing parse and the
legacy reader.
…§2.10)

The helpers read the R2000+ flag-then-value forms on every release, which
only agrees with the R13-R14 form when thickness is 0 and the extrusion is
(0,0,1). Measured on Cabin.dwg: 18 LINE and 2 POLYLINE_2D records with a
non-default thickness or extrusion now end exactly on their RL boundary.
The synthetic R14 LINE of tests/integration_legacy_container.rs wrote the
one-bit defaults the old reader assumed; it writes the BD and 3BD §2.8 and
§2.10 print.
§20.4.44 prints 'R14 Only' for the RC after Numitems; R13 writes nothing
there. 88 R13 DICTIONARY records missed their RL boundary (by 8 bits
when the dictionary is empty).
…over the R13-R14 branches added since (#119)

header_vars.rs matched Version exhaustively, so the R13 variant needs its
own arm: the table already carries the R13 rows. MTEXT's and LWPOLYLINE's
R13-R14 branches (#261, #264) were written as 'is R14'. Cabin.dwg's 195
header slots end on the stated size; the probe also reports the 21 Sovol
headers, which hold 84 bits more than any table reads.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:07:45.600152Z — New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

, #119)

The 21 Sovol R13 drawings write the four 'R14+' unknown shorts of §9 (each
-1; §9 says they 'do not seem to be required') after the R13 slots, and size
the header one byte past the byte holding the last slot, so the R13 rows
left 84 bits and the Corpus job's header probe failed on them. An AC1012
header whose R13 rows leave a whole byte or more is now read with the R14
rows and may end one byte before its data; Cabin.dwg and every other release
read as before. All 22 R13 headers, 199 slots on the Sovol drawings, now
decode to the stated size.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0c186b7b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/probe_r13_container.rs Resolved
… header-variable failure (#119)

The header-variable arm printed FAIL without setting the exit status, so a
drawing that passed the framing checks but did not decode to its stated end
reported success. Every failure line now goes through one emit that sets it,
including a file that fails to open and a missing object map or header.
Conflicts: ARCHITECTURE.md (the R13 section is 7ac, after main's 7ab),
docs/data/spec-coverage.tsv and docs/spec-coverage.md (my row notes appended
to main's, §3 and §23 kept), src/entities/dispatch.rs (main's R13/R14
DIMSTYLE arm kept as main wrote it; the BT/BE decode_for routing kept), and
tools/corpus/baseline.tsv regenerated: main's rows unchanged, 22 R13 rows
added.
…R14 (#119)

#320 matched Version exhaustively; the AC1012 variant it was written
without made clippy --all-targets fail on the merged tree.
…riters (#119, #345)

Autodesk's own R13 discs pad 0000 in 196 of 263 headers and 1111 in 6.
What holds on every AutoCAD-written header: 195 slots, a section of exactly
ceil(bits / 8), three or four locators and a real preview. The Sovol files
are not AutoCAD's on the extra header byte, the blank preview and the
R2007+ SUN object. The byte after 18 in section 26's tail varies on
Autodesk's own files, so Cabin's 18 30 is not evidence against AutoCAD.
…cator layout still waits for Autodesk's discs (#345)
…sha256 and what was read (#119, #345)

Griffin decided on 2026-10-26 that these drawings are measured and cited,
never pinned, fetched by CI or committed. docs/data/r13-autodesk-discs.tsv
has one row per distinct drawing; the ARCHITECTURE section cites the 3- and
4-locator layouts, the 195-slot ceil(bits / 8) header, the padding spread and
the real previews from it.
…ies and probe_dxf_tables map R13 to no DXF writer, as R14 (#119)

Main matches Version exhaustively in the three probes, so clippy
--all-targets does not compile them once Version::R13 exists.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/version.rs
return Err(Error::NotDwg { got: *magic });
}
Ok(match magic {
b"AC1012" => Self::R13,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep R13 on the primitive DXF export path

For an AC1012 drawing with a closed header and decoded layers, conversion to R2000-or-later DXF silently drops all geometry. Accepting R13 here exposes the existing dxf_entities::writes() predicate, which excludes only R14, so dxf_convert::convert() selects the handle-aware exporter instead of its primitive fallback. However, handle_stream_start() returns None for R13 records, and the entity_refs() error makes dxf_entities::build() skip every entity; the converter then returns a successful but empty export. Exclude R13 alongside R14 in the exporter-selection predicate until its handle references are supported.

Useful? React with 👍 / 👎.

DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
* fix(ci): hold a stacked PR until the older PR it builds on lands

A PR stacked on an older open PR targets main but holds that PR's commits. When the train held the
older PR on a review thread it went on to the next one: landed first, that PR would have carried the
older one's work into main under its own title (#337 over #335, #339 over #337 were drafted by hand
to stop it), and its refresh merged main over the older PR's commits, so after that PR landed its
merge base no longer applied and a lane had to merge it by hand. The train now sends such a PR to
the end of the queue while an older open PR (a lower number) shares commits with it that main does
not have. On the queue of 2026-10-28: #324 waits for #323, #355 for #324, #356 for #355, #410 for
#356, #412 for #410, #339 for #337 and #341 for #339; #323, #337, #389 and #296 wait for nothing.

* fix(ci): check every open PR, skip landed work, and defer on a failed lookup

The stack check listed at most 200 open PRs, only those targeting main, treated any shared commit as
outstanding even when it belonged to a PR that had already landed by squash, and let a PR through
when a fetch or gh call failed. It now fetches every PR head to refs/train/pr/<n> in the main clone,
pages through all open PRs whatever they target, ignores a shared commit that a merged PR's head
holds, and returns 2 on any failed lookup, which sends the PR to the end of the queue. Checked in a
scratch repository (two PRs built on a landed PR do not wait for each other; a PR built on another
waits for it; a failing gh returns 2) and on the live queue, where the R13 and unp stacks give the
same order as before.

* fix(ci): count only PRs merged into main as landed when checking a stack

A PR merged into a feature branch has merged_at set too, so its commits were treated as landed and a
newer PR holding them went ahead of the open PR they were waiting in. The exemption now takes only
PRs whose base is main. All 187 merged PRs so far target main, so the live order is unchanged.

This branch has not been deployed

No deployments
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.

1 participant