Merge pull request #3123 from hammerlink/master
Prevent crashes from `svg` rendering
This commit is contained in:
commit
b02db5e6f8
2 changed files with 23 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ use tiny_skia::Transform;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::hash_map;
|
use std::collections::hash_map;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::panic;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -171,7 +172,15 @@ impl Cache {
|
||||||
tiny_skia::Transform::default()
|
tiny_skia::Transform::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
resvg::render(tree, transform, &mut image.as_mut());
|
// SVG rendering can panic on malformed or complex vectors.
|
||||||
|
// We catch panics to prevent crashes and continue gracefully.
|
||||||
|
let render = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
|
resvg::render(tree, transform, &mut image.as_mut());
|
||||||
|
}));
|
||||||
|
|
||||||
|
if let Err(error) = render {
|
||||||
|
log::warn!("SVG rendering for {handle:?} panicked: {error:?}");
|
||||||
|
}
|
||||||
|
|
||||||
if let Some([r, g, b, _]) = key.color {
|
if let Some([r, g, b, _]) = key.color {
|
||||||
// Apply color filter
|
// Apply color filter
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use resvg::tiny_skia;
|
||||||
use resvg::usvg;
|
use resvg::usvg;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::panic;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Entry in cache corresponding to an svg handle
|
/// Entry in cache corresponding to an svg handle
|
||||||
|
|
@ -154,7 +155,18 @@ impl Cache {
|
||||||
tiny_skia::Transform::default()
|
tiny_skia::Transform::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
resvg::render(tree, transform, &mut img.as_mut());
|
// SVG rendering can panic on malformed or complex vectors.
|
||||||
|
// We catch panics to prevent crashes and continue gracefully.
|
||||||
|
let render =
|
||||||
|
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
|
resvg::render(tree, transform, &mut img.as_mut());
|
||||||
|
}));
|
||||||
|
|
||||||
|
if let Err(error) = render {
|
||||||
|
log::warn!(
|
||||||
|
"SVG rendering for {handle:?} panicked: {error:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let mut rgba = img.take();
|
let mut rgba = img.take();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue