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:
Brandon Thomas
2026-10-04 13:24:14 -04:00
co-authored by Claude Opus 5.5
parent 10644a83aa
commit 1da7dc4659
6 changed files with 40 additions and 6 deletions
+28
View File
@@ -725,3 +725,31 @@ fn text_style_runs_export_as_range_animators() {
// Played back as an animator, it looks the same.
compare_renders(&p, cid, &q, nc, 2.0 / 255.0);
}
#[test]
fn extreme_enum_numbers_do_not_overflow() {
// Line cap / join / merge mode / text-selector enums are 1-based; a huge negative number
// (-1e308 rounds to i64::MIN) overflowed the `- 1`.
let path = format!("{}/tests/fixtures/shapes-gradient.json", env!("CARGO_MANIFEST_DIR"));
let mut doc: Json = serde_json::from_slice(&std::fs::read(path).unwrap()).unwrap();
let mut hits = 0;
fn patch(j: &mut Json, hits: &mut usize) {
match j {
Json::Object(o) => {
for k in ["lc", "lj", "mm"] {
if o.contains_key(k) {
o.insert(k.into(), json!(-1e308));
*hits += 1;
}
}
o.values_mut().for_each(|v| patch(v, hits));
}
Json::Array(a) => a.iter_mut().for_each(|v| patch(v, hits)),
_ => {}
}
}
patch(&mut doc, &mut hits);
assert!(hits > 0);
let mut q = Project::default();
import(&mut q, doc.to_string().as_bytes(), "x", "", &mut |_| None).unwrap();
}