From dda8ac628186809877559ed20eb7633ccf008a5e Mon Sep 17 00:00:00 2001 From: lucas persson <4030216+luben93@users.noreply.github.com> Date: Sat, 31 Oct 2026 18:10:56 +0100 Subject: [PATCH] [ai] raw: test split strips with up to four extra fixed-rate rows The end-of-strip rule accepts whole fixed-rate rows past the image (up to 4), but no test covered a valid strip with such rows. Encode 1 to 5 extra rows at 12 and 14 bit: up to 4 decode with the image rows unchanged, the fifth is refused (preview fallback). Suggested by CodeRabbit on #10529. Co-Authored-By: Claude Opus 5.5 --- crates/raw/src/nefc/tests.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/raw/src/nefc/tests.rs b/crates/raw/src/nefc/tests.rs index 5eb72c7bc68..76701208dbc 100644 --- a/crates/raw/src/nefc/tests.rs +++ b/crates/raw/src/nefc/tests.rs @@ -556,3 +556,26 @@ fn split_files_failing_after_the_table_still_fall_back_to_the_preview() { let cut = file.len() - 40; assert!(unsupported(decode_raw(&file[..cut], &Limits::default()))); } + +#[test] +fn split_strips_with_up_to_four_extra_rows_are_accepted() { + // A strip may hold whole fixed-rate rows past the image (one body stores 4022 rows for + // 4020): up to 4 such rows decode, the image rows unchanged; a fifth is refused. + for bits in [12u32, 14] { + let huff = if bits == 12 { &LOSSY_12 } else { &LOSSY_14 }; + let (w, h, split) = (24usize, 7usize, 3usize); + let t = split_table(bits, split); + let Encoding::Lossy(curve) = &t.encoding else { panic!() }; + let max = curve.len() as i32 - 1; + for extra in 1..=5 { + let (src, recon) = encode_split(&gentle(w, h + extra, 600), w, huff, t.seeds, bits, split); + let got = decode(&src, w, h, bits, &t); + if extra <= 4 { + let want: Vec = recon[..w * h].iter().map(|&r| curve[r.clamp(0, max) as usize]).collect(); + assert_eq!(got.unwrap(), want, "{bits}-bit, {extra} extra rows"); + } else { + assert!(matches!(got, Err(RawError::Unsupported(_))), "{bits}-bit, {extra} extra rows: {got:?}"); + } + } + } +}