Repository navigation
Never crash: strip byte counts near u64::MAX don't overflow their sum in ORF, SRW, ARW and PEF - #3386
Conversation
… in ORF, SRW, ARW and PEF The TIFF reader accepts LONG8 (type 16) StripByteCounts in classic TIFF, so a file can declare strips of u64::MAX and 1 bytes. The ORF, SRW, ARW and PEF decoders added the strip lengths with Iterator::sum::<u64>(), which panics on overflow in debug builds. They now add them with a saturating fold, as raw/src/lib.rs already does, so such a file is refused or read as far as its data go. The tests rewrite a synthetic file of each decoder into two strips with LONG8 counts [u64::MAX, 1] (vendor::tests::huge_strip_counts); PEF is checked for the Huffman-coded and the uncompressed path.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Decoder totals and regression coverage crates/raw/src/vendor.rs, crates/raw/src/vendor/{arw,orf,pef,srw}.rs, docs/whats-new.md |
The four decoders now use saturating addition for strip byte counts. Tests construct totals above u64::MAX and invoke decoding in header and full modes. The release notes describe the handling of these files. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
storytold/lightcraft#2561— This change prevents aggregateu64overflow in the related decoders, but does not add the issue’s real-slice validation before allocation.
Suggested reviewers: radialmonster
Merge Risk: 
Minimal · up to 1c906
-
The targeted overflow is addressed, and no actionable merge-blocking risk is established.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 5 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
* Port upstream #3385: a mask id at the u32 limit no longer overflows Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Port upstream #3386: strip byte counts past u64::MAX do not overflow Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Port upstream #3384: a SAM 3 checkpoint in Meta's format is named as such Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Port upstream #3390: the Flatpak may talk to the accessibility bus Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
The ORF, SRW, ARW and PEF decoders added up their strip byte counts with
.sum::<u64>():orf.rs:209srw.rs:100arw.rs:631pef.rs:270and:277The classic-TIFF reader accepts LONG8 values (types 16 to 18), so a file whose StripByteCounts are
[u64::MAX, 1]overflows that sum. In debug builds that panics in both probe and decode; in release the sum wraps. Each site now usesfold(0u64, |a, c| a.saturating_add(c.len)), asraw/src/lib.rsalready does. A saturated sum then fails the decoders' existing size checks as usual.Tests:
strip_byte_counts_past_u64_max_do_not_overflowinvendor::{orf,srw,arw,pef}::tests. Each runs the Header and Full modes. They use a shared helper invendor.rstests that rewrites a built one-strip file into two strips with LONG8 counts[u64::MAX, 1]. The PEF test covers both the Huffman (65535) and the uncompressed path. All four panic on main.Notes:
tiff/reader.rsis unchanged (LR-META-EXIF: TIFF keeps shared child IFDs and multi-string ASCII values #3002 touches it).docs/whats-new.md, so whichever merges second has a trivial conflict there: join the entries under one heading.Checked on macOS (M1 Pro): fmt, clippy,
cargo test --workspace --no-fail-fast, parity, layers, assets and wasm. The only failures are the same onmainhere (445dd31):if_same_then_elseinapps/lightcraft/src/native_menu.rs;accessibility::every_interactive_node_has_a_name_in_every_view_and_tool(no craft-fonts checkout for the ▸ glyph);ci_quick::tests::embedded_files_are_mapped(fixed on main since by Fix update testing and track the embedded updater icon in CI #3365);lightcraft-mcp(backend::tests::idle_close_reconnects_without_replaying_a_command,e2e::*timing out on this Mac, see #1952: the idle-close MCP test reads blocking and waits for the close #2627).🤖 Generated with Claude Code
Summary by CodeRabbit