Skip to content

feat(entities): decode the §20.4.41 ACIS record and settle the AcDs marker - #67

Merged
DrunkOnJava merged 1 commit into
mainfrom
feat/acis-entity-tails
Aug 30, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
feat/acis-entity-tails

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Decodes the whole §20.4.41 ACIS record — REGION (37), 3DSOLID (38), BODY (39) — and uses the three records that carry it to settle the width of the R2013+ has AcDs binary data marker (#54), which this crate had been reading three different ways.

Spec reference

§20.4.41 REGION (37) / 3DSOLID (38) / BODY (39) prescribes one record shape for all three, and §24.2.2.3 explains what R2013 changed: "For each ACIS entity (REGION, 3DSOLID), a data record is created with the SAB stream of the object." The geometry payload leaves the entity record and becomes a data record in AcDb:AcDsPrototype_1b, flagged by the record's has AcDs binary data bit.

The field list

The corpus holds exactly three ACIS records, all in sample_AC1032.dwg (R2018), and all three set that bit. Measured from bit 82 — where the common entity preamble ends on all three — to each record's data-stream boundary:

B     wireframe data present          1
B     point present                   1
3BD   point
BL    num isolines                    4
B     isolines present                1
BL    num wires                       0
BL    num silhouettes                 0
B     ACIS empty (2)                  1     -- §20.4.41 "Normally 1"
BL    unknown (R2007+)                0
--- R2013+ data-store block, measured ---
B     unknown_a                       1
BB    unknown_b                       0
BB    unknown_c
BB    unknown_d
RC×16 revision GUID
BL    unknown_e                       0

The inline ACIS envelope is absent: only two bits stand between the preamble and the point, and both are 1.

record data ends point isolines revision GUID delta
3DSOLID 0xD65 bit 437 (17.7767…, -220.8501…, 2.5) 4 833111a1-b7ac-4dd4-824d-78b33668f9e7 0
REGION 0xD69 bit 373 (24.9857…, -220.4000…, 0) 4 2b80e3b3-b594-475e-8593-6a36b15e7945 0
3DSOLID 0xD6A bit 437 (31.6857…, -220.1073…, 2.1902…) 4 f21ff2a0-ff9c-4ed1-9b2e-7a1e6518d595 0

Four corroborations independent of the arithmetic:

  1. The points are drawing geometry — three bodies in a row at y ≈ -220, x stepping 17.8 → 25.0 → 31.7. Every rejected candidate produced 1e+88-scale doubles instead.
  2. num isolines is 4 on all three — AutoCAD's default ISOLINES value.
  3. The 16 bytes are a valid RFC-4122 version-4 UUID on all three (version nibble 4, variant bits 10). Scanning every 128-bit window of all three records, data_end - 130 is the only alignment where all three satisfy both; three independent windows doing that by chance is 1 in 2^18.
  4. Everything else is the spec's own grammar, decoding the values §20.4.41 says to expect.

Only the width of the seven bits before the GUID is measured. The three records agree on 1, 0 for the first two slots and differ after, so B, BB, BB, BB is a labelling, not a measurement, and the module says so. The per-wire and per-silhouette payloads are stepped exactly but not surfaced — no corpus record carries any, so structs for them would be API no byte has exercised.

The #54 arbitration

#52 measured 16 bits after the flag on four LAYOUT records; tables/modern.rs measured an RC on DIMSTYLE; common_entity.rs read 0, untested, because no entity record whose field list closed had ever set the bit. These three ACIS records are that missing case.

examples/probe_acis_records.rs re-reads the preamble at each candidate width and runs §20.4.41 from wherever it lands:

marker width preamble ends preamble values §20.4.41 list
0 bits bit 82 colour 0x0100, lts 1.0, invis 0, lw 0x1D delta 0
8 bits — does not read (reserved BD pattern 11) —
16 bits bit 148–212 colour 0xEE10, lts 0 (or 1.5e119), lw 0x10 / 0x12 / 0xBC does not close

Both halves fail together at every non-zero width. At 0 bits the preamble decodes exactly the values every other entity in the file carries — BYLAYER colour 0x0100, linetype scale 1.0, invisibility 0, lineweight 0x1D; at 16 bits it decodes none of them, and the field list is then short of its boundary.

Verdict: the flag is a flag — nothing follows it. common_entity.rs and objects/modern.rs now agree on 0 bits. The 16 bits four R2018 LAYOUT records need moved into src/objects/acad_layout.rs as LAYOUT's own two-byte data-store block at the head of its §20.4.84 list, still conditional on the flag and still closing all 31 corpus LAYOUT records. tables/modern.rs keeps its RC: that path also omits the BL num_reactors the object path reads, so its bit accounting has a second unresolved variable and is out of scope here. Three record types needing three different widths is itself the argument that the width belongs to the record, not to the flag.

Two spec-conformance fixes that fell out

The envelope reader carried two departures from §20.4.41 that no corpus record had ever reached:

  • the B unknown bit between ACIS empty and BS version was not read at all;
  • the block loop read a B has_more_blocks flag before each BL block size, where the spec terminates the loop on a block size of 0 and has no such flag.

Both are corrected, and version 2 — "immediately following will be an acis file … no length is given" — is now refused rather than mis-stepped. Four surface tests that had written the old shape are updated.

Measured coverage

cargo run --release --example coverage_report -- ../../samples, 19-file corpus, re-measured on the merged tree (origin/main = 7418d25, merge is a no-op — already up to date):

Corpus slice Before (7418d25) After
R2004 (AC1018) × 3 510 / 87 / 0 / 85.4 % 510 / 87 / 0 / 85.4 %
R2010 (AC1024) × 3 531 / 12 / 0 / 97.8 % 531 / 12 / 0 / 97.8 %
R2013 (AC1027) × 3 384 / 12 / 0 / 97.0 % 384 / 12 / 0 / 97.0 %
R2018 (AC1032) × 1 762 / 80 / 0 / 90.5 % 765 / 77 / 0 / 90.9 %
Aggregate 2187 / 191 / 0 / 92.0 % 2190 / 188 / 0 / 92.1 %

Zero errored records, before and after. Every previously-closed decoder still closes, including all 31 LAYOUT records after their 16 bits were relocated.

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo test --release passes — 741 lib tests (+7), all integration suites green
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features passes
  • cargo deny check all passes
  • cargo +1.85.0 test --no-run passes (MSRV)
  • New BitWriter round-trip tests for the data-store record, the inline-envelope record, exact wire/silhouette stepping, and the absurd-count rejection
  • New real-DWG regression test sample_ac1032_acis_records_close_on_their_boundary pins in_data_store, num_isolines == 4, y ≈ -220, and the RFC-4122 version/variant nibbles of each GUID
  • Coverage-report numbers attached above

Source-provenance declaration

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 ODA's freely-redistributable Open Design Specification for .dwg files v5.4.1 (§20.4.41 for the record shape, §24.2.2.3 for the data-storage semantics, §20.4.1 for the common entity data) and the bytes 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 field name and type in the new field list comes from the §20.4.41 table itself, including the spec's own gloss "Normally 1" on the second ACIS-empty bit. The R2013+ data-store block is measured — the residue between the end of that grammar and each record's data-stream boundary — and the only word not taken from the spec is "revision GUID", which the RFC-4122 version-4 structure earns. The seven bits before it are labelled unknown_*; only their width is claimed. CLEANROOM.md records this.
  4. I have never had access to any forbidden source in a commercial or NDA'd context.

By submitting this PR I also certify compliance with the Developer Certificate of Origin 1.1.

Closes #61
Closes #54

https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C


Note

Medium Risk
Changes bit accounting on common entity/object prefixes and adds substantial ACIS field parsing; misalignment would corrupt geometry, but decoders self-check against data-stream boundaries and corpus tests pin the three R2018 ACIS records and LAYOUT closure.

Overview
Implements the full §20.4.41 record for REGION, 3DSOLID, and BODY (shared modeler path): wireframe/isoline tail, optional inline SAT envelope, and the measured R2013+ data-store block (revision GUID) when has AcDs binary data is set. 3DSOLID, REGION, and BODY are now first-class DecodedEntity variants with boundary-checked decode_record on R2010+.

#54: The R2013+ has AcDs binary data bit is treated as a flag with no following bits on the entity path (common_entity). The 16 bits previously consumed in objects/modern for LAYOUT move into acad_layout as a conditional two-byte ds_block at the start of §20.4.84; object prefix only records the flag via has_ds_binary_data.

ACIS envelope reading is aligned with the spec: read the unknown B, terminate the version-1 block loop on BL == 0 (no has_more_blocks), and reject version 2 instead of guessing length.

Adds probe_acis_records, real-DWG regression on sample_AC1032.dwg, and updates coverage docs (2190 decoded / 188 skipped / 92.1% aggregate; R2018 765 / 77 / 90.9%).

Reviewed by Cursor Bugbot for commit b28f62d. Configure here.

…arker

REGION (37), 3DSOLID (38) and BODY (39) are one entry in the ODA
specification and one field list here. The crate read only the ACIS
envelope's first bit; the rest of §20.4.41 — the wireframe / point /
isoline block, the wire and silhouette structures, the second
ACIS-empty bit and the R2007+ trailing BL — is now decoded, and the
three types dispatch through the boundary-checked entity path.

All three ACIS records of the corpus (sample_AC1032.dwg 3DSOLID 0xD65 /
0xD6A, REGION 0xD69, R2018) set the R2013+ `has AcDs binary data` bit,
so their SAB stream is a data record in the data-storage section
(§24.2.2.3) and no inline envelope is written. After the spec's grammar
they carry 137 further bits: seven whose tokenisation the corpus cannot
separate, a 16-byte revision GUID, and a BL. The list closes at delta 0
on all three, corroborated by three real coordinate triples at y ≈ -220,
`num isolines = 4` (AutoCAD's ISOLINES default) on every record, and a
valid RFC-4122 version-4 UUID at the one 128-bit alignment all three
share.

That closes #54. The `has AcDs binary data` flag is followed by nothing:
common_entity.rs and objects/modern.rs now agree on 0 bits, and the 16
bits four R2018 LAYOUT records need moved into acad_layout.rs as
LAYOUT's own data-store block, still closing all 31 corpus LAYOUTs.
tables/modern.rs keeps its RC — that path also omits the BL reactor
count, so its accounting has a second unresolved variable.

Two spec-conformance fixes fell out of the same section: the envelope
now reads the `B unknown` bit between the empty bit and the version, and
its block loop terminates on a zero block size instead of a fabricated
per-block flag. Version 2 (a raw ACIS file with no length) is refused
rather than mis-stepped.

Measured on the 19-file corpus:

| slice | before | after |
|---|---|---|
| R2018 (AC1032) × 1 | 762 / 80 / 0 / 90.5% | 765 / 77 / 0 / 90.9% |
| aggregate | 2187 / 191 / 0 / 92.0% | 2190 / 188 / 0 / 92.1% |

Closes #61
Closes #54

Claude-Session: https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C
@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_0977bd8f-924a-4bbd-887f-c2f036d78fb2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant