From 19dcd09e09044a635af36282abcf3b197377a1d4 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Tue, 10 Mar 2026 05:22:35 -0600 Subject: [PATCH] fix: panic on unknown ColorType in hash, fix rfind in hash helper - compute_tiff_hash now panics on unhandled ColorType variants instead of silently using a fallback discriminant - print_seq_hashes correctly identifies existing 8-char hex hash suffix vs non-hash filename segments --- tests/decode_images.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/decode_images.rs b/tests/decode_images.rs index c278bee..4840cde 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -108,7 +108,7 @@ fn compute_tiff_hash(reader: R) -> u32 { hasher.update(&[9, bit_depth]); hasher.update(&num_samples.to_le_bytes()); } - _ => hasher.update(&[255]), + other => panic!("compute_tiff_hash: unhandled ColorType {other:?}"), } // Hash decoded data with type discriminant + LE sample bytes @@ -286,9 +286,16 @@ fn print_seq_hashes() { let name = path.file_name().unwrap().to_str().unwrap(); let file = File::open(&path).expect("Cannot open test image"); let hash = format!("{:08x}", compute_tiff_hash(file)); - // Strip the old hash (last -XXXXXXXX before .tiff) and print with new hash + // Strip the old hash (last -XXXXXXXX before .tiff) if present let stem = path.file_stem().unwrap().to_str().unwrap(); - let base = &stem[..stem.rfind('-').unwrap_or(stem.len())]; + let base = match stem.rsplit_once('-') { + Some((prefix, suffix)) + if suffix.len() == 8 && suffix.chars().all(|c| c.is_ascii_hexdigit()) => + { + prefix + } + _ => stem, + }; let new_name = format!("{base}-{hash}.tiff"); if new_name != name { eprintln!("RENAME: {name} -> {new_name}");