Never crash: Lottie enum values can't overflow
Lottie stores line cap, line join, merge mode and some text-selector enums 1-based, and the importer subtracted 1 from whatever number the file held: -1e308 (rounded to i64::MIN) overflowed, a panic in debug builds (found by structural fuzzing). Use saturating_sub. Denies the panic lints in the crate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10644a83aa
commit
1da7dc4659
@@ -363,7 +363,7 @@ pub(crate) fn import_text(im: &mut Im, ids: &mut Ids, t: &Json, tg: &mut PropGro
|
||||
let mut en = |m: &str, key: &str, max: u32| {
|
||||
let v = s.get(key).and_then(|v| if v.is_object() { v.get("k") } else { Some(v) }).and_then(anim::nums).and_then(|n| n.first().copied());
|
||||
if let (Some(v), Some(p)) = (v, adv.get_mut(m)) {
|
||||
p.value = Value::Enum(((v.round() as i64 - 1).max(0) as u32).min(max));
|
||||
p.value = Value::Enum((((v.round() as i64).saturating_sub(1)).max(0) as u32).min(max));
|
||||
}
|
||||
};
|
||||
en("units", "r", 1);
|
||||
|
||||
Reference in New Issue
Block a user