From 786c5571f05595276857e7faa36c8be2fe895a7d Mon Sep 17 00:00:00 2001 From: techneissa <55485515+techneissa@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:39:50 +0300 Subject: [PATCH] raw: refuse an understated DNG strip whose ActiveArea reaches below the image (#2040) decode drops such an ActiveArea for the whole image, so nothing would explain the short byte count. --- crates/raw/src/dng.rs | 2 +- crates/raw/src/dng/compat_review_tests.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/raw/src/dng.rs b/crates/raw/src/dng.rs index a7be5d67b..f62aeef47 100644 --- a/crates/raw/src/dng.rs +++ b/crates/raw/src/dng.rs @@ -546,7 +546,7 @@ fn extend_understated_strip(bytes: &[u8], info: &mut ImageInfo, raw: &Ifd) { } let ([offset], [count]) = (&info.offsets[..], &info.byte_counts[..]) else { return }; let Some([top, left, bottom, right]) = raw.u64s(t::ACTIVE_AREA).and_then(|a| <[u64; 4]>::try_from(a).ok()) else { return }; - if left != 0 || bottom <= top || right == 0 || right >= u64::from(info.width) { + if left != 0 || bottom <= top || bottom > u64::from(info.height) || right == 0 || right >= u64::from(info.width) { return; } let row_bytes = |width: u64| width.checked_mul(u64::from(info.height))?.checked_mul(bits / 8); diff --git a/crates/raw/src/dng/compat_review_tests.rs b/crates/raw/src/dng/compat_review_tests.rs index 309d1e5b7..149ee492d 100644 --- a/crates/raw/src/dng/compat_review_tests.rs +++ b/crates/raw/src/dng/compat_review_tests.rs @@ -170,6 +170,8 @@ fn other_short_strips_are_still_refused() { assert!(refused(understated_strip_dng(8, 4, 6 * 4 * 2, None))); // the count is not exactly the area's bytes assert!(refused(understated_strip_dng(8, 4, 5 * 4 * 2, Some([0, 0, 4, 6])))); + // the area reaches below the image, so decode would discard it + assert!(refused(understated_strip_dng(8, 4, 6 * 4 * 2, Some([4, 0, 5, 6])))); // the area does not start at column 0 assert!(refused(understated_strip_dng(8, 4, 6 * 4 * 2, Some([0, 2, 4, 8])))); // the file does not hold the whole raster