mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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 <mukilan@igalia.com>
This commit is contained in:
parent
64b872ec0d
commit
ee2acaeacf
1 changed files with 5 additions and 3 deletions
|
@ -158,9 +158,11 @@ impl From<PrefValue> 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::<Vec<f64>>();
|
||||
let f = values
|
||||
.into_iter()
|
||||
.filter_map(|v| v.try_into().ok())
|
||||
.collect::<Vec<f64>>();
|
||||
if f.len() == 4 {
|
||||
[f[0], f[1], f[2], f[3]]
|
||||
} else {
|
||||
panic!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue