From 71e271483380e211f38e7d49c0765c59cff6e785 Mon Sep 17 00:00:00 2001 From: techneissa <55485515+techneissa@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:47:47 +0300 Subject: [PATCH] raw: lengthen an understated DNG strip only for integer samples (#2040) SampleFormat 4 and other undefined values no longer reach the extension; an absent tag still reads as 1 (unsigned), so a file without it is unchanged. --- crates/raw/src/dng.rs | 2 +- crates/raw/src/dng/compat_review_tests.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/raw/src/dng.rs b/crates/raw/src/dng.rs index f62aeef47..9589f5d4d 100644 --- a/crates/raw/src/dng.rs +++ b/crates/raw/src/dng.rs @@ -539,7 +539,7 @@ fn extend_understated_strip(bytes: &[u8], info: &mut ImageInfo, raw: &Ifd) { || info.compression != t::compression::NONE || info.samples_per_pixel != 1 || info.planar == 2 - || info.sample_format == 3 + || !matches!(info.sample_format, 1 | 2) || !matches!(bits, 8 | 16) { return; diff --git a/crates/raw/src/dng/compat_review_tests.rs b/crates/raw/src/dng/compat_review_tests.rs index 149ee492d..7fcc1b4f4 100644 --- a/crates/raw/src/dng/compat_review_tests.rs +++ b/crates/raw/src/dng/compat_review_tests.rs @@ -122,7 +122,15 @@ fn decoded_notices_record_actual_crop_gain_table_and_cfa_decisions() { /// A 16-bit CFA DNG of `width` x `height` whose strip holds every row in full but whose `StripByteCounts` says /// `counted` bytes. fn understated_strip_dng(width: u32, height: u32, counted: u32, active_area: Option<[u32; 4]>) -> Vec { + understated_strip_dng_with(width, height, counted, active_area, &[]) +} + +/// [`understated_strip_dng`] with `extra` tags set on the raw IFD. +fn understated_strip_dng_with(width: u32, height: u32, counted: u32, active_area: Option<[u32; 4]>, extra: &[(u16, Value)]) -> Vec { let mut raw = IfdBuilder::new(); + for (tag, value) in extra { + raw.set(*tag, value.clone()); + } for (tag, value) in [ (t::IMAGE_WIDTH, Value::Long(vec![width])), (t::IMAGE_LENGTH, Value::Long(vec![height])), @@ -170,6 +178,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])))); + // samples that are neither integer nor absent-format (SampleFormat 4 is undefined) + assert!(refused(understated_strip_dng_with(8, 4, 6 * 4 * 2, Some([0, 0, 4, 6]), &[(t::SAMPLE_FORMAT, Value::Short(vec![4]))]))); // 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