From ee2acaeacf2bdb522815358b8c9b87a09208f118 Mon Sep 17 00:00:00 2001 From: Mukilan Thiyagarajan Date: Thu, 20 Jun 2024 14:17:13 +0530 Subject: [PATCH] config: fix panic in PrefValue to [f64; 4] conversion (#32571) The `Iterator::all` method consumes the input iterator `f` so when we reuse `f` in `f.flatten().collect()` it yields an empty Vector in the case where all the elements are successfully converted using try_into(). This causes out of bounds access when indexing into the resulting Vector to extract the individual components. Fixes #32570. Signed-off-by: Mukilan Thiyagarajan --- components/config/pref_util.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/config/pref_util.rs b/components/config/pref_util.rs index d8cfa78aaea..c0def153d44 100644 --- a/components/config/pref_util.rs +++ b/components/config/pref_util.rs @@ -158,9 +158,11 @@ impl From for [f64; 4] { fn from(other: PrefValue) -> [f64; 4] { match other { PrefValue::Array(values) if values.len() == 4 => { - let mut f = values.into_iter().map(|v| v.try_into()); - if f.all(|v| v.is_ok()) { - let f = f.flatten().collect::>(); + let f = values + .into_iter() + .filter_map(|v| v.try_into().ok()) + .collect::>(); + if f.len() == 4 { [f[0], f[1], f[2], f[3]] } else { panic!(