From 2b518b55fe65340a2bc62f3a271c8b7963022556 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 22 Oct 2026 10:58:54 +0200 Subject: [PATCH] Reject non-finite values when parsing .cube LUTs Found while testing crates/pipeline/src/lut.rs:25 (Lut3d::parse_cube, the `three` helper) Co-Authored-By: Claude Opus 5.5 --- crates/pipeline/src/lut.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/pipeline/src/lut.rs b/crates/pipeline/src/lut.rs index b66c3444e..fccb34e8f 100644 --- a/crates/pipeline/src/lut.rs +++ b/crates/pipeline/src/lut.rs @@ -24,7 +24,7 @@ impl Lut3d { let mut data = Vec::new(); let three = |rest: &str| -> Option<[f32; 3]> { let v: Vec = rest.split_whitespace().filter_map(|x| x.parse().ok()).collect(); - (v.len() == 3).then(|| [v[0], v[1], v[2]]) + (v.len() == 3 && v.iter().all(|x| x.is_finite())).then(|| [v[0], v[1], v[2]]) }; for line in text.lines() { let l = line.trim(); @@ -140,4 +140,19 @@ mod tests { assert!(Lut3d::parse_cube("LUT_1D_SIZE 4\n0 0 0").is_err()); assert!(Lut3d::parse_cube("LUT_3D_SIZE 2\n0 0 0\n").is_err(), "too few entries"); } + + #[test] + fn non_finite_entries_rejected() { + let bad_line = |body: &str| { + let e = Lut3d::parse_cube(body).expect_err(body); + assert!(e.starts_with("bad line"), "{e}"); + }; + bad_line(&format!("LUT_3D_SIZE 2\n{}", "-inf inf nan\n".repeat(8))); + bad_line(&format!("LUT_3D_SIZE 2\n{}", "1e39 0 0\n".repeat(8))); + bad_line(&format!("LUT_3D_SIZE 2\n-inf 0 0\n{}", "0 0 0\n".repeat(7))); + let ok = cube(|c| c, 2); + assert!(Lut3d::parse_cube(&ok).is_ok()); + assert!(Lut3d::parse_cube(&format!("DOMAIN_MIN nan 0 0\n{ok}")).is_err()); + assert!(Lut3d::parse_cube(&format!("DOMAIN_MAX inf 1 1\n{ok}")).is_err()); + } }