fix: prevent crashes from SVG rendering

This commit is contained in:
Hendrik Hamerlinck 2025-11-14 19:39:36 +01:00 • committed by Ashley Wulber
parent 484aa0a532
commit 9b636e281b
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820

View file

@ -175,12 +175,17 @@ impl Cache {
// SVG rendering can panic on malformed or complex vectors. // SVG rendering can panic on malformed or complex vectors.
// We catch panics to prevent crashes and continue gracefully. // We catch panics to prevent crashes and continue gracefully.
let render = panic::catch_unwind(panic::AssertUnwindSafe(|| { let render_result =
resvg::render(tree, transform, &mut image.as_mut()); panic::catch_unwind(panic::AssertUnwindSafe(|| {
})); resvg::render(tree, transform, &mut image.as_mut());
}));
if let Err(error) = render { if render_result.is_err() {
log::warn!("SVG rendering for {handle:?} panicked: {error:?}"); log::warn!(
"SVG rendering panicked for handle ID: {}",
handle.id()
);
return None;
} }
if let Some([r, g, b, _]) = key.color { if let Some([r, g, b, _]) = key.color {