Try to render corrupt SVGs after panic

This commit is contained in:
Héctor Ramón Jiménez 2025-12-01 17:01:40 +01:00
parent d845ac27db
commit 4cc7eb47f7
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 12 additions and 17 deletions

View file

@ -5,7 +5,8 @@ use crate::image::atlas::{self, Atlas};
use resvg::tiny_skia;
use resvg::usvg;
use rustc_hash::{FxHashMap, FxHashSet};
use std::{fs, panic};
use std::fs;
use std::panic;
use std::sync::Arc;
/// Entry in cache corresponding to an svg handle
@ -156,17 +157,15 @@ impl Cache {
// SVG rendering can panic on malformed or complex vectors.
// We catch panics to prevent crashes and continue gracefully.
let render_result =
let render =
panic::catch_unwind(panic::AssertUnwindSafe(|| {
resvg::render(tree, transform, &mut img.as_mut());
}));
if render_result.is_err() {
if let Err(error) = render {
log::warn!(
"SVG rendering panicked for handle ID: {}",
handle.id()
"SVG rendering for {handle:?} panicked: {error:?}"
);
return None;
}
let mut rgba = img.take();