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