[librsvg/librsvg-2.44] (#335): Don't panic if the toplevel node is not <svg>
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.44] (#335): Don't panic if the toplevel node is not <svg>
- Date: Tue, 18 Sep 2018 21:17:38 +0000 (UTC)
commit 82fd014e43f1792183aa3b0c7cc1269d47c2e83b
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Sep 13 08:01:27 2018 -0500
(#335): Don't panic if the toplevel node is not <svg>
In standard_element_start(), we were only setting the tree root if the
first element in the file was an <svg> element. Otherwise we would
simply unref the element at the end of the function. This caused its
first child to be left with weak reference to a dead parent; the
subsequent call to child.get_parent() would upgrade().unwrap() on the
weak reference, and the unwrap() would panic as the parent is already
dead.
https://gitlab.gnome.org/GNOME/librsvg/issues/335
librsvg/rsvg-load.c | 7 +++----
rsvg_internals/src/load.rs | 17 -----------------
tests/fixtures/crash/335-non-svg-toplevel.svg | 1 +
3 files changed, 4 insertions(+), 21 deletions(-)
---
diff --git a/librsvg/rsvg-load.c b/librsvg/rsvg-load.c
index 40996eae..f3f3bdbe 100644
--- a/librsvg/rsvg-load.c
+++ b/librsvg/rsvg-load.c
@@ -40,7 +40,7 @@ typedef enum {
/* Implemented in rsvg_internals/src/load.rs */
G_GNUC_INTERNAL
-RsvgNode *rsvg_load_new_node (const char *element_name, RsvgNode *parent, RsvgPropertyBag *atts, RsvgDefs
*defs, gboolean *is_svg);
+RsvgNode *rsvg_load_new_node (const char *element_name, RsvgNode *parent, RsvgPropertyBag *atts, RsvgDefs
*defs);
/* Implemented in rsvg_internals/src/load.rs */
G_GNUC_INTERNAL
@@ -298,18 +298,17 @@ standard_element_start (RsvgLoad *load, const char *name, RsvgPropertyBag * atts
{
RsvgDefs *defs;
RsvgNode *newnode;
- gboolean is_svg;
defs = rsvg_handle_get_defs(load->handle);
- newnode = rsvg_load_new_node(name, load->currentnode, atts, defs, &is_svg);
+ newnode = rsvg_load_new_node(name, load->currentnode, atts, defs);
push_element_name (load, name);
if (load->currentnode) {
rsvg_node_add_child (load->currentnode, newnode);
load->currentnode = rsvg_node_unref (load->currentnode);
- } else if (is_svg) {
+ } else {
load->tree = rsvg_tree_new (newnode);
}
diff --git a/rsvg_internals/src/load.rs b/rsvg_internals/src/load.rs
index 8327ea6c..248dd313 100644
--- a/rsvg_internals/src/load.rs
+++ b/rsvg_internals/src/load.rs
@@ -1,5 +1,3 @@
-use glib::translate::*;
-use glib_sys;
use libc;
use std::collections::HashMap;
@@ -272,7 +270,6 @@ pub extern "C" fn rsvg_load_new_node(
parent: *const RsvgNode,
pbag: *const PropertyBag,
defs: *mut RsvgDefs,
- out_is_svg: *mut glib_sys::gboolean,
) -> *const RsvgNode {
assert!(!raw_name.is_null());
assert!(!pbag.is_null());
@@ -308,25 +305,11 @@ pub extern "C" fn rsvg_load_new_node(
let node = create_fn(id, class, parent);
assert!(!node.is_null());
- let is_svg = {
- let n: &RsvgNode = unsafe { &*node };
- match n.get_type() {
- NodeType::Invalid => unreachable!(),
- NodeType::Svg => true,
- _ => false,
- }
- };
-
if id.is_some() {
let n = unsafe { &*node };
defs.insert(id.unwrap(), n);
}
- assert!(!out_is_svg.is_null());
- unsafe {
- *out_is_svg = is_svg.to_glib();
- }
-
node
}
diff --git a/tests/fixtures/crash/335-non-svg-toplevel.svg b/tests/fixtures/crash/335-non-svg-toplevel.svg
new file mode 100644
index 00000000..f9aefcbe
--- /dev/null
+++ b/tests/fixtures/crash/335-non-svg-toplevel.svg
@@ -0,0 +1 @@
+<x><x></x>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]