From bf31b6527123afbcd3fc53be041ba51e3afe213d Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 18 Nov 2026 15:38:08 +0530 Subject: [PATCH] #3830: keep four .3dl tokens and a spare mesh row at small limits --- crates/effects/src/ocio/lut.rs | 6 ++++-- crates/effects/src/ocio/tests.rs | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/effects/src/ocio/lut.rs b/crates/effects/src/ocio/lut.rs index 6868dff46..8424e33cd 100644 --- a/crates/effects/src/ocio/lut.rs +++ b/crates/effects/src/ocio/lut.rs @@ -59,7 +59,7 @@ pub(super) fn parse_3dl_limited(text: &str, max_side: usize) -> Option { } continue; } - let v: Vec = l.split_whitespace().filter_map(|t| t.parse().ok()).take(max_side.saturating_add(1)).collect(); + let v: Vec = l.split_whitespace().filter_map(|t| t.parse().ok()).take(max_side.max(3).saturating_add(1)).collect(); if v.len() > 3 && mesh.is_none() && rows.is_empty() { // The mesh length is the lattice side: refuse one no lattice reader accepts (#3830). if v.len() > max_side { @@ -67,7 +67,9 @@ pub(super) fn parse_3dl_limited(text: &str, max_side: usize) -> Option { } mesh = Some(v); } else if v.len() == 3 { - if rows.len() >= max_side.saturating_pow(3) { + // One spare row while no mesh is known: a 3-entry mesh reads as a data row until the + // count tells them apart below. + if rows.len() >= max_side.saturating_pow(3).saturating_add(usize::from(mesh.is_none())) { return None; } rows.push([v[0], v[1], v[2]]); diff --git a/crates/effects/src/ocio/tests.rs b/crates/effects/src/ocio/tests.rs index a11fe32f5..afeabea22 100644 --- a/crates/effects/src/ocio/tests.rs +++ b/crates/effects/src/ocio/tests.rs @@ -583,4 +583,9 @@ fn a_3dl_lattice_is_capped_at_the_largest_side() { assert!(lut::parse_3dl_limited(&table_3dl(5, mesh), 4).is_none(), "mesh {mesh}"); assert!(lut::parse_3dl_limited(&table_3dl(5, mesh), 5).is_some(), "mesh {mesh}"); } + // A 3-entry mesh reads as a 28th row until the count separates it, and a four-value row is + // still refused at the smallest limit. + assert!(lut::parse_3dl_limited(&table_3dl(3, true), 3).is_some_and(|l| l.n3 == 3)); + let four = table_3dl(2, false).replacen("7 7 7", "7 7 7 7", 1); + assert!(lut::parse_3dl_limited(&four, 2).is_none()); }