Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Reject .3dl LUTs whose input mesh is larger than 256 entries

NetterSilverc08f3bff1568
diff --git a/crates/color/src/lut.rs b/crates/color/src/lut.rs
index ac5642ac7..67590eb12 100644
--- a/crates/color/src/lut.rs
+++ b/crates/color/src/lut.rs
@@ -368,6 +368,9 @@ impl Lut {
}
let mesh = mesh.ok_or("empty .3dl")?;
let n = mesh.len();
+ if !(2..=256).contains(&n) {
+ return Err(format!("input mesh must have 2–256 values, found {n}"));
+ }
if rows.len() != n * n * n {
return Err(format!("expected {}³ = {} rows, found {}", n, n * n * n, rows.len()));
}
@@ -638,4 +641,13 @@ mod tests {
assert!(Lut::parse(&text, None).is_ok());
assert_eq!(LutFormat::from_path("a/b/Look.CUBE"), Some(LutFormat::Cube));
}
+
+ #[test]
+ fn huge_3dl_mesh_is_rejected() {
+ let text = (0..1u32 << 22).map(|i| i.to_string()).collect::<Vec<_>>().join(" ") + "\n";
+ let r = std::panic::catch_unwind(|| Lut::parse_3dl(&text).map(|l| l.apply([0.5; 3])));
+ assert!(matches!(r, Ok(Err(_))), "huge mesh must be rejected without panicking");
+ let mesh257 = (0..257).map(|i| i.to_string()).collect::<Vec<_>>().join(" ") + "\n";
+ assert!(Lut::parse_3dl(&mesh257).is_err());
+ }
}