Skip to content

fix(r2007): a header offset or length that overflows is a truncated file, not a panic - #271

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/r2007-offset-overflow
Oct 26, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
fix/r2007-offset-overflow

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

A header-supplied offset or length that overflows in the R2007 container is now a truncated-file error instead of a panic (debug and fuzz builds) or a silent wrap (release).

Spec reference

§5.3 system pages, §5.4 section map, §5.10/§5.13 data pages: every offset and length these read comes from the file.

Found by the fuzz nightly on its first strict run after #232 (run 40310363468): dwg_file_open panicked at src/r2007.rs:353 with "attempt to add with overflow". load_system_page builds span with saturating multiplies and then slices bytes[offset..offset + span], so a hostile header makes span equal to usize::MAX and the sum overflow. The same unchecked start + len pattern was at four more sites: the file-header payload, section-map names and both data-page paths. All five now use checked_range(start, len), which returns None on overflow, so each falls into the Truncated/SectionMap error it already reported. align_up saturates.

Test plan

  • Reproduced with the real crash input (committed as fuzz/corpus/dwg_file_open/regress_r2007_offset_overflow.bin): a debug dwg-info built from main exits 101, panicked at src/r2007.rs:353:34: attempt to add with overflow; built from this branch, it exits 0 and lists the container as _R2007_UNREADABLE, the reader's existing fallback.
  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings
  • Behaviour on well-formed files is unchanged: checked_range equals the old range whenever the sum fits; the Corpus job confirms decode counts
  • No unit tests added; the regression lives in the fuzz corpus

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

Developer Certificate of Origin

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

…ile, not a panic

The fuzz nightly (#187, made able to fail by #232) found it on its first strict run: dwg_file_open panicked at src/r2007.rs:353 with 'attempt to add with overflow'. load_system_page computed span with saturating multiplies, then sliced bytes[offset..offset + span]; a hostile header makes span usize::MAX, so the sum overflows (a panic in debug and fuzz builds, a silent wrap in release).

The same unchecked offset + length pattern sat at four more places that take both values from the file: the file-header payload (0x20 + stored), section-map names (pos + name_len) and data pages (base + span, base + compressed). All five now build their range with checked_range(start, len), which is None on overflow, so each falls into the Truncated or SectionMap error it already reported. align_up saturates instead of overflowing.

The crash input is committed as a dwg_file_open fuzz seed. On it, a debug dwg-info built from main exits 101 with the panic; built from this branch, it exits 0 and reports the container as _R2007_UNREADABLE, the reader's existing fallback.
@DrunkOnJava DrunkOnJava added type:bug Something reads, writes or reports wrongly area:container File organization R13 to R2018 (spec §3 to §8, §11, §26) area:fuzz Fuzz targets and their corpora release:R2007 Affects R2007 files priority:P1 On the path of the current milestone 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-26T11:13:19.744484Z 5039563 PR opened
ℹ️ 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 11:16
@DrunkOnJava
DrunkOnJava merged commit 0e66009 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/r2007-offset-overflow branch October 26, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:container File organization R13 to R2018 (spec §3 to §8, §11, §26) area:fuzz Fuzz targets and their corpora priority:P1 On the path of the current milestone release:R2007 Affects R2007 files type:bug Something reads, writes or reports wrongly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant