File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use tiny_skia::Transform;
88use std:: cell:: RefCell ;
99use std:: collections:: hash_map;
1010use std:: fs;
11+ use std:: panic;
1112use std:: sync:: Arc ;
1213
1314#[ derive( Debug ) ]
@@ -171,7 +172,15 @@ impl Cache {
171172 tiny_skia:: Transform :: default ( )
172173 } ;
173174
174- resvg:: render ( tree, transform, & mut image. as_mut ( ) ) ;
175+ // SVG rendering can panic on malformed or complex vectors.
176+ // We catch panics to prevent crashes and continue gracefully.
177+ let render = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
178+ resvg:: render ( tree, transform, & mut image. as_mut ( ) ) ;
179+ } ) ) ;
180+
181+ if let Err ( error) = render {
182+ log:: warn!( "SVG rendering for {handle:?} panicked: {error:?}" ) ;
183+ }
175184
176185 if let Some ( [ r, g, b, _] ) = key. color {
177186 // Apply color filter
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use resvg::tiny_skia;
66use resvg:: usvg;
77use rustc_hash:: { FxHashMap , FxHashSet } ;
88use std:: fs;
9+ use std:: panic;
910use std:: sync:: Arc ;
1011
1112/// Entry in cache corresponding to an svg handle
@@ -154,7 +155,18 @@ impl Cache {
154155 tiny_skia:: Transform :: default ( )
155156 } ;
156157
157- resvg:: render ( tree, transform, & mut img. as_mut ( ) ) ;
158+ // SVG rendering can panic on malformed or complex vectors.
159+ // We catch panics to prevent crashes and continue gracefully.
160+ let render =
161+ panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
162+ resvg:: render ( tree, transform, & mut img. as_mut ( ) ) ;
163+ } ) ) ;
164+
165+ if let Err ( error) = render {
166+ log:: warn!(
167+ "SVG rendering for {handle:?} panicked: {error:?}"
168+ ) ;
169+ }
158170
159171 let mut rgba = img. take ( ) ;
160172
You can’t perform that action at this time.
0 commit comments