Repository navigation
fix(r2007): a header offset or length that overflows is a truncated file, not a panic - #271
Merged
Merged
Conversation
…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.
2 tasks
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_openpanicked atsrc/r2007.rs:353with "attempt to add with overflow".load_system_pagebuildsspanwith saturating multiplies and then slicesbytes[offset..offset + span], so a hostile header makesspanequal tousize::MAXand the sum overflow. The same uncheckedstart + lenpattern was at four more sites: the file-header payload, section-map names and both data-page paths. All five now usechecked_range(start, len), which returnsNoneon overflow, so each falls into theTruncated/SectionMaperror it already reported.align_upsaturates.Test plan
fuzz/corpus/dwg_file_open/regress_r2007_offset_overflow.bin): a debugdwg-infobuilt 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 warningschecked_rangeequals the old range whenever the sum fits; the Corpus job confirms decode countsSource-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:
Developer Certificate of Origin
By submitting this PR, I certify that the contribution complies with the Developer Certificate of Origin 1.1.