Skip to content

fix(handle-map): a section smaller than its own CRC is an error, not a panic - #231

Merged
DrunkOnJava merged 3 commits into
mainfrom
fix/handle-map-short-section
Oct 26, 2026
Merged

DrunkOnJava merged 3 commits into
mainfrom
fix/handle-map-short-section

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

HandleMap::parse panics on an AcDb:Handles section whose big-endian size is 1: the size covers the section's own 2-byte CRC, so pos + section_size - 2 puts the payload slice at [2..1]. A size below 2 is now an Error::SectionMap, as the crate's malformed-input invariant requires. Found by the fuzz nightly once it could fail (#232); refs #187.

Spec reference

§23.1 (AcDb:Handles, the object map; §23.2 says R2004+ is identical after decompression): each section is a big-endian short size, the handle/offset MC pairs, then a 2-byte CRC, and the list repeats "until section size==2 (the last empty (except the CRC) section)", so the size counts the CRC. A size of 1 cannot hold it and is malformed. The parser's existing treatment of 0 as the end of the list is unchanged.

Test plan

Both crash inputs the dispatched fuzz run found (run 40296541245) go through the real entry point, dwg::handle_map::HandleMap::parse, from an out-of-tree binary:

$ xxd section_map-crash.bin
00000000: 0001 0004 0a00 0000                      ........
$ xxd handlemap_parse-crash.bin
00000000: 0001 0000 0010 1234 0000                 .......4..

before (main d76a3ed):
thread 'main' panicked at src/handle_map.rs:102:33:
slice index starts at 2 but ends at 1

after:
section_map-crash.bin: Err: Section map parse failed: AcDb:Handles section at byte 0 claims 1 bytes, less than its own 2-byte CRC
handlemap_parse-crash.bin: Err: Section map parse failed: AcDb:Handles section at byte 0 claims 1 bytes, less than its own 2-byte CRC

Both inputs are committed as named seeds (fuzz/corpus/{section_map,handlemap_parse}/regress_section_size_1.bin), so every fuzz run replays them before mutating: the regression fixture #187 asks for, run through the fuzz targets themselves rather than a unit test.

Local fuzzing with the fix, cargo +nightly fuzz run <target> -- -max_total_time=60 -print_final_stats=1:

section_map      Done 2286461 runs in 61 second(s)   peak_rss_mb 681   no crash
handlemap_parse  Done 2047345 runs in 61 second(s)   peak_rss_mb 703   no crash

Replaying each committed seed directory, new seeds included (-runs=0): section_map 5 files, handlemap_parse 4 files, no crash.

Real files: cargo run --release --example coverage_report -- ../../samples over the 19-file corpus is byte-identical before and after (TOTAL 3911 decoded, 525 skipped, 9 errored; "Handle-map self-check: 0 record(s) carry a handle that disagrees with the map"; "every handle-map entry resolved to a record").

  • cargo fmt --all -- --check
  • No unit tests 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 is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

Based on §23.1 and §23.2 of the ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1) and the module's existing documentation of the section layout. No third-party code or comments were read.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the Developer Certificate of Origin 1.1.

…a panic

HandleMap::parse took a big-endian section size of 1 at face value and sliced the payload as [pos..pos-1], panicking. §23.1 counts the section's 2-byte CRC in its size (the list ends at size 2), so a size of 1 is malformed and now returns Error::SectionMap. Both fuzz targets that reach the parser found it within seconds once the nightly could fail; their crash inputs are committed as named seeds so every fuzz run replays them. Refs #187.
@DrunkOnJava DrunkOnJava added type:bug Something reads, writes or reports wrongly area:handles AcDb:Handles object map (spec §23) area:fuzz Fuzz targets and their corpora labels Oct 26, 2026
@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-26T10:31:31.525835Z e65449e 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.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 09:43
@DrunkOnJava
DrunkOnJava disabled auto-merge October 26, 2026 09:44
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 10:30
@DrunkOnJava
DrunkOnJava merged commit 945cd99 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/handle-map-short-section branch October 26, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fuzz Fuzz targets and their corpora area:handles AcDb:Handles object map (spec §23) type:bug Something reads, writes or reports wrongly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant