Skip to content

feat(sections): decode every AcDb:Header variable from one table (§9, #126) - #302

Merged
DrunkOnJava merged 7 commits into
mainfrom
feat/header-vars-table
Oct 26, 2026
Merged

DrunkOnJava merged 7 commits into
mainfrom
feat/header-vars-table

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

Decodes every variable of AcDb:Header (§9) from one table, R14 to R2018, with the R2007+ string and handle streams, and holds the result to every pinned drawing's DXF export. Closes #126.

This is one PR rather than a pre-R2007 family first: every release closes and agrees, and cutting it would leave a probe that fails on 36 of the 52 files. Say if you want it split.

Spec reference

ODA v5.4.1 §9, with §2.11 (CMC), §2.13 (handles) and the §19.1 object layout for the R2007+ streams. ARCHITECTURE.md §7n records the frame, the stream plan and where §9 differs from the files. R13 (AC1012) has no file in the corpus, so its rows are the table's and unmeasured.

  • src/header_table.rs: the table, a row per slot in stream order (bit code, first and last release, AutoCAD name or UNKNOWN_<code>_<n>).
  • src/header_vars.rs: frame (sentinels, size, CRC), the three streams, typed Values, HeaderVars::{decode, parse_strict, parse_lossy, get, unknowns}; DwgFile::header_vars_strict. The section is bounded by the new ParseLimits::max_header_bytes; every length is checked before use and every failure is an Error.
  • examples/probe_header_vars.rs (dxf-reader feature), wired into the Corpus job.
  • fuzz/fuzz_targets/header_vars.rs wraps its input in a valid frame (both sentinels, a fitting size, the CRC) for every release so it reaches the slot decoder; 47,191 runs over seeds of the 52 real sections found nothing.
  • examples/spec_examples.rs: the spec's own R14 header dump now decodes in full (199 slots, every stream on its boundary), not just its first four BDs.
  • §9 row in docs/data/spec-coverage.tsv is closes, not complete: R13 has no file and no AC1014 export exists.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • Shown working on real files, no new unit tests:
    cargo run --release --features dxf-reader --example probe_header_vars -- <dwg-corpus> over the 52 pinned drawings:
release        files closed twins  slots unknown  agree  relation  disagree DWG-only DXF-only
AC1014 (R14)       8      8     8   1592     120   1279        57         0      264      392
AC1015 (2000)      8      8     8   1888     112   1670        42         0      184       40
AC1018 (2004)      8      8     8   2072     208   1765        51         0      264       48
AC1021 (2007)      8      8     8   2432     232   2093        51         0      296       48
AC1024 (2010)      8      8     8   2472     232   2109        43         0      328       48
AC1027 (2013)      8      8     8   2488     240   2103        57         0      336       48
AC1032 (2018)      4      4     2   1244     120    525        15         0       84       12
TOTAL             52     52    50  14188    1264  11544       316         0     1756      636

Padding after the last slot is all ones on 52 of 52. The AC1014 twin is the AC1015 export of the same drawing (no AC1014 export exists). Without arguments the probe reads ../../samples (19 drawings, no twins there): 19 of 19 close.

  • cargo run --release --example spec_examples passes, with the new §9 decode.
  • CI is the first full-suite run: the local cargo test --release --all-features was held by the governor and did not complete; cargo test --lib header (25 tests) passed after the rebase.

Findings (§9 against the files)

MENUNAME is read on every release (§9 says R13-R18); four unknown BS end the section on every release from R14 and five B follow them from R2004, in the handle stream from R2007; the padding is ones (the spec's 1998 R14 dump differs, so the probe counts and does not require it); R2000 and later hold universal time in what §9 calls TDCREATE/TDUPDATE (named $TDUCREATE/$TDUUPDATE); a CMC from R2004 keeps its meaning in the top byte of its BL; the unknown B before INTERFERECOLOR and the last unknown BD are $REALWORLDSCALE and $SHADOWPLANELOCATION. The 316 relations are listed by rule in §7n (twin saved later, per-save VERSIONGUID, case-insensitive names, leading-underscore arrowhead blocks, XCLIPFRAME 2 written false before R2010, the default visual style DXF fills in on R2013+, a true colour written as an approximate index).

Existing tests changed

In src/header_vars.rs: removed parse_strict_accepts_sentinel_prefix and parse_reads_sentinel_and_size (they asserted that a 21- or 23-byte "section" with no CRC or end sentinel parses and that the size word counts bits; §9's size counts bytes and the section is at least 58 bytes); adapted parse_strict_errors_on_short_input (wanted 20 became the 58-byte minimum); kept the three lossy-parse tests unchanged. No test added.

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 (v5.4.1) is the source of the table.
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

The only other inputs: the public corpus (byte inspection and AutoCAD's own DXF exports), and AutoCAD's published lineweight list for lineweight_hundredths (named in its doc comment; index 29 is the only entry the corpus measures). No algorithm-description comments in other projects were read.

Developer Certificate of Origin

I affirm the contribution is my own work and may be distributed under the project's Apache-2.0 license.

…126)

src/header_table.rs holds §9 as one table, a row per slot in stream order with
its bit code and first and last release; src/header_vars.rs walks the rows of
the file's release. R14 to R2018: 311 slots on R2018, each under its AutoCAD
name ($INSBASE, $EXTMIN, $DIMTAD, ...) or named UNKNOWN_<code>_<n>.

R2007 and later read the data, string and handle streams the way an object
does. The size in bits counts from 32 bits before the data and ends at the
first handle bit; the string stream is found backwards from there.

All 52 pinned drawings pass both sentinels, the size, the CRC and every stream
boundary. examples/probe_header_vars.rs compares every variable with
AutoCAD's DXF export of the same drawing: 11,544 agree, 316 hold a stated
relation (case-insensitive names, a later save, a per-save GUID, a clamped
flag), 0 disagree. The spec's own R14 header dump decodes in full
(examples/spec_examples.rs). The Corpus job runs the probe; the header_vars
fuzz target wraps its input in a valid frame for every release so it reaches
the slot decoder.

§9 differs from the files in ways ARCHITECTURE.md §7n records: MENUNAME is
read on every release, four BS and (from R2004) five B end the section, the
padding is ones, R2000 and later store universal time, and a CMC from R2004
keeps its meaning in the top byte of its BL.
@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-26T15:14:48.091506Z 17dbf39 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.

# Conflicts:
#	.github/workflows/ci.yml
#	docs/spec-coverage.md

@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: 1a2b4b8d03

ℹ️ 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/header_vars.rs Resolved
Comment thread src/header_vars.rs Resolved
… its index (§9, #126)

An R2007+ header whose strings-present bit is clear has no string stream to
end, so the strings-end boundary is checked only when one exists. The decoded
entries are read through HeaderVars::entries(): the field is private so a
caller cannot reorder or clear it under the name index and make get() answer
for another variable or index out of bounds.

@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: 028ba2695e

ℹ️ 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/header_vars.rs Resolved
…(§9, #126)

R14 to R2004 store text in the drawing's code page, which the crate does not
apply; reading it as UTF-8 returned a corrupted string with no diagnostic. A
text with a byte above 0x7F is now Value::RawText with its bytes; ASCII text is
Value::Text as before. Nothing in the corpus has such text.
# Conflicts:
#	.github/workflows/ci.yml
#	ARCHITECTURE.md
#	docs/spec-coverage.md

@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: 00a4cb40ba

ℹ️ 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/header_vars.rs Resolved

@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: 922543a2f0

ℹ️ 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/header_vars.rs Resolved
… short string stream (§9, #126)

parse_lossy checked the beginning sentinel only in strict mode and the CRC
excludes those 16 bytes, so a damaged first sentinel left a clean-looking
result; it is now a diagnostic. From R2007, with the strings-present bit set,
a text slot read after the string stream is exhausted is an error instead of
an implicit empty string, so a shortened stream no longer yields empty
variables that still close.
# Conflicts:
#	ARCHITECTURE.md
#	docs/spec-coverage.md
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.

A table-driven header decoder with release ranges

1 participant