From eb809af5bb7e3e0f87952568836a2106e66664f7 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:31:13 +0100 Subject: [PATCH] raw hostile tests: a fixed sample by default, the full sweep under PHOTOCRAFT_FULL_SWEEP=1 (#15938) every_truncation_fails_cleanly tried every 3rd length of every seed and random_corruption_never_panics 400 corruptions per seed. They now take the first and last 16 lengths, every 7th length in the first 2 KiB and about 300 lengths per seed past it, and 40 corruptions per seed from a stream of its own. PHOTOCRAFT_FULL_SWEEP=1 runs every length and 400 corruptions. Most of the truncation time went to the RW2 seed, whose data is padded to a 16 KiB block: about 2,300 cuts in the padding that decode the same zeros. --- crates/raw/tests/it/hostile.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/raw/tests/it/hostile.rs b/crates/raw/tests/it/hostile.rs index 7ae2287b690..b04d93ce9f6 100644 --- a/crates/raw/tests/it/hostile.rs +++ b/crates/raw/tests/it/hostile.rs @@ -157,10 +157,23 @@ fn a_seed_states_a_maker_note_colour_space() { assert!(samples().iter().any(|b| embedded_preview_color_space(b) == Some(PreviewColorSpace::AdobeRgb))); } +/// Whether the fuzz tests below run every case instead of their fixed sample: `PHOTOCRAFT_FULL_SWEEP=1`, +/// the switch `photocraft_testkit::Sweep` reads (this standalone crate cannot depend on the testkit). +fn full_sweep() -> bool { + std::env::var_os("PHOTOCRAFT_FULL_SWEEP").is_some_and(|v| v == "1") +} + #[test] fn every_truncation_fails_cleanly() { + // The fixed sample: the first and last 16 lengths, which cut the header and the last bytes of + // the sensor data, every 7th length in the first 2 KiB, and about 300 lengths per file past it. + // Only the RW2 seed is much longer: RW2 pads its data to a 16 KiB block, so its cuts past 2 KiB + // all decode the same zeros, and every 7th of them cost more than the rest of the test. + // The full sweep tries every length. + let full = full_sweep(); for b in samples() { - for n in (0..b.len()).step_by(3) { + let step = |n: usize| if n < 2048 { 7 } else { (b.len() / 300).max(7) }; + for n in (0..b.len()).filter(|&n| full || n % step(n) == 0 || n < 16 || n + 16 >= b.len()) { exercise(&b[..n]); } } @@ -168,13 +181,15 @@ fn every_truncation_fails_cleanly() { #[test] fn random_corruption_never_panics() { - let mut s = 0xDEAD_BEEF_u64; - let mut next = || { - s = s.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); - s >> 33 - }; - for b in samples() { - for _ in 0..400 { + let cases = if full_sweep() { 400 } else { 40 }; + for (i, b) in samples().iter().enumerate() { + // A stream per file, so the fixed sample is the start of the full sweep's. + let mut s = 0xDEAD_BEEF_u64 ^ (i as u64 + 1).wrapping_mul(0x9E37_79B9_7F4A_7C15); + let mut next = || { + s = s.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); + s >> 33 + }; + for _ in 0..cases { let mut c = b.clone(); for _ in 0..1 + next() % 6 { let at = next() as usize % c.len();