[librsvg: 2/4] pattern: Don't panic when trying to resolve with an empty bounding box
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/4] pattern: Don't panic when trying to resolve with an empty bounding box
- Date: Fri, 12 Nov 2021 01:29:55 +0000 (UTC)
commit f9e15ff9a85b3e0b02f31b6297295b38a70d36c0
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Nov 11 17:46:21 2021 -0600
pattern: Don't panic when trying to resolve with an empty bounding box
This got triggered from DrawingCtx::with_discrete_layer(), where it
tries to resolve the paint servers to pass on to the filters code.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/631>
src/pattern.rs | 7 ++++++-
tests/fixtures/render-crash/gradient-with-empty-bbox.svg | 14 ++++++++++++++
tests/fixtures/render-crash/pattern-with-empty-bbox.svg | 16 ++++++++++++++++
tests/src/render_crash.rs | 2 +-
4 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/pattern.rs b/src/pattern.rs
index 96778e401..5d887266d 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -337,7 +337,12 @@ impl ResolvedPattern {
let params = NormalizeParams::new(values, &view_params);
let rect = self.get_rect(¶ms);
- let bbrect = bbox.rect.unwrap();
+
+ let bbrect = match bbox.rect {
+ None => return None,
+ Some(r) if r.is_empty() => return None,
+ Some(r) => r,
+ };
// Create the pattern coordinate system
let (width, height, coord_transform) = match self.units {
diff --git a/tests/fixtures/render-crash/gradient-with-empty-bbox.svg
b/tests/fixtures/render-crash/gradient-with-empty-bbox.svg
new file mode 100644
index 000000000..d98b5cfb3
--- /dev/null
+++ b/tests/fixtures/render-crash/gradient-with-empty-bbox.svg
@@ -0,0 +1,14 @@
+<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="grad1">
+ </linearGradient>
+ <radialGradient id="grad2">
+ </radialGradient>
+ </defs>
+
+ <!-- Use an empty group with a filter, so it will try to resolve the stroke/fill paint servers.
+ Since the group has no children, the paint servers will get an empty bbox.
+ -->
+ <g fill="url(#grad1)" filter="opacity(0.5)"/>
+ <g fill="url(#grad2)" filter="opacity(0.5)"/>
+</svg>
diff --git a/tests/fixtures/render-crash/pattern-with-empty-bbox.svg
b/tests/fixtures/render-crash/pattern-with-empty-bbox.svg
new file mode 100644
index 000000000..8ffa7daf4
--- /dev/null
+++ b/tests/fixtures/render-crash/pattern-with-empty-bbox.svg
@@ -0,0 +1,16 @@
+<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <pattern id="pat1" patternUnits="objectBoundingBox">
+ <circle cx="5" cy="5" r="5" fill="lime"/>
+ </pattern>
+ <pattern id="pat2" patternUnits="userSpaceOnUse">
+ <circle cx="5" cy="5" r="5" fill="lime"/>
+ </pattern>
+ </defs>
+
+ <!-- Use an empty group with a filter, so it will try to resolve the stroke/fill paint servers.
+ Since the group has no children, the paint servers will get an empty bbox.
+ -->
+ <g fill="url(#pat1)" filter="opacity(0.5)"/>
+ <g fill="url(#pat2)" filter="opacity(0.5)"/>
+</svg>
diff --git a/tests/src/render_crash.rs b/tests/src/render_crash.rs
index ce8dfc72b..f89285d32 100644
--- a/tests/src/render_crash.rs
+++ b/tests/src/render_crash.rs
@@ -10,7 +10,7 @@ use cairo;
use librsvg::{CairoRenderer, Loader};
#[test_resources("tests/fixtures/render-crash/*.svg")]
-fn loading_crash(path: &str) {
+fn render_crash(path: &str) {
let handle = Loader::new()
.read_path(path)
.unwrap_or_else(|e| panic!("could not load: {}", e));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]