Skip to content

Commit b788625

Browse files
hammerlinkwash2
authored andcommitted
fix: prevent crashes from SVG rendering
1 parent 16b1f1f commit b788625

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tiny_skia/src/vector.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use tiny_skia::Transform;
77

88
use std::cell::RefCell;
99
use std::collections::hash_map;
10-
use std::fs;
1110
use std::sync::Arc;
11+
use std::{fs, panic};
1212

1313
#[derive(Debug)]
1414
pub struct Pipeline {
@@ -169,7 +169,20 @@ impl Cache {
169169
tiny_skia::Transform::default()
170170
};
171171

172-
resvg::render(tree, transform, &mut image.as_mut());
172+
// SVG rendering can panic on malformed or complex vectors.
173+
// We catch panics to prevent crashes and continue gracefully.
174+
let render_result =
175+
panic::catch_unwind(panic::AssertUnwindSafe(|| {
176+
resvg::render(tree, transform, &mut image.as_mut());
177+
}));
178+
179+
if render_result.is_err() {
180+
log::warn!(
181+
"SVG rendering panicked for handle ID: {}",
182+
handle.id()
183+
);
184+
return None;
185+
}
173186

174187
if let Some([r, g, b, _]) = key.color {
175188
// Apply color filter

0 commit comments

Comments
 (0)