[librsvg: 8/9] (#308): Don't exhaust the stack on recursive <use>



commit 9f7a8450af6ad7118e2c9fe1a206edadd032a619
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 15 10:56:23 2019 -0500

    (#308): Don't exhaust the stack on recursive <use>
    
    This was not handled properly because our <use> implementation did
    this:
    
    - Acquire the node referenced by <use xlink:href="#foo"/>
    
    - Clone the node referene, causing the AcquiredNode to be dropped...
    
    - ... so that the node reference is "free" now, outside of the
    AcquiredNodes stack...
    
    - ... so that if the node somehow ends up referencing itself as a
    clipPath or a mask or something, it will work.
    
    I.e. doing cycle detection with our old scheme made the test for
    761175-recursive-masks.svg fail, since it <use>s a group which
    in turn contains a <use href="#foo" mask="#mask-which-uses-foo"/>.
    
    With the new cycle detection scheme, only <use> and elements which are
    referenced indirectly (patterns, gradients, filters, etc.) get put
    into the AcquiredNodes stack.  This seems to find cycles properly
    while not breaking that particular test.
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/308

 tests/errors.c                                     | 13 +++++++++++++
 tests/fixtures/errors/308-doubly-recursive-use.svg | 13 +++++++++++++
 tests/fixtures/errors/308-recursive-use.svg        |  9 +++++++++
 tests/fixtures/errors/308-use-self-ref.svg         |  7 +++++++
 4 files changed, 42 insertions(+)
---
diff --git a/tests/errors.c b/tests/errors.c
index ea1e3c2e..e03c97ba 100644
--- a/tests/errors.c
+++ b/tests/errors.c
@@ -83,6 +83,19 @@ main (int argc, char **argv)
                                test_instancing_limit,
                                NULL);
 
+    g_test_add_data_func_full ("/errors/instancing_limit/308-use-self-ref.svg",
+                               "308-use-self-ref.svg",
+                               test_instancing_limit,
+                               NULL);
+    g_test_add_data_func_full ("/errors/instancing_limit/308-recursive-use.svg",
+                               "308-recursive-use.svg",
+                               test_instancing_limit,
+                               NULL);
+    g_test_add_data_func_full ("/errors/instancing_limit/308-doubly-recursive-use.svg",
+                               "308-doubly-recursive-use.svg",
+                               test_instancing_limit,
+                               NULL);
+
     g_test_add_data_func_full ("/errors/515-too-many-elements.svgz",
                                "515-too-many-elements.svgz",
                                test_loading_error,
diff --git a/tests/fixtures/errors/308-doubly-recursive-use.svg 
b/tests/fixtures/errors/308-doubly-recursive-use.svg
new file mode 100644
index 00000000..9b248a6f
--- /dev/null
+++ b/tests/fixtures/errors/308-doubly-recursive-use.svg
@@ -0,0 +1,13 @@
+<svg>
+  <defs>
+    <g id="one">
+      <use xlink:href="#two"/>
+    </g>
+
+    <g id="two">
+      <use xlink:href="#one"/>
+    </g>
+  </defs>
+
+  <use xlink:href="#one"/>
+</svg>
diff --git a/tests/fixtures/errors/308-recursive-use.svg b/tests/fixtures/errors/308-recursive-use.svg
new file mode 100644
index 00000000..f5d00bf2
--- /dev/null
+++ b/tests/fixtures/errors/308-recursive-use.svg
@@ -0,0 +1,9 @@
+<svg>
+  <defs>
+    <g id="one">
+      <use xlink:href="#one"/>
+    </g>
+  </defs>
+
+  <use xlink:href="#one"/>
+</svg>
diff --git a/tests/fixtures/errors/308-use-self-ref.svg b/tests/fixtures/errors/308-use-self-ref.svg
new file mode 100644
index 00000000..dbf14c54
--- /dev/null
+++ b/tests/fixtures/errors/308-use-self-ref.svg
@@ -0,0 +1,7 @@
+<svg>
+  <defs>
+    <use id="one" xlink:href="#one"/>
+  </defs>
+
+  <use xlink:href="#one"/>
+</svg>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]