[librsvg/librsvg-2.42: 2/8] Increase the number of elements acquired on each acquisition



commit 6b76125e1c00f325c2125c5bdf07e612a9021168
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 25 10:45:51 2020 -0600

    Increase the number of elements acquired on each acquisition

 librsvg/rsvg-base.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 6f2fec55..47b75982 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -1641,6 +1641,18 @@ rsvg_push_discrete_layer (RsvgDrawingCtx * ctx)
     ctx->render->push_discrete_layer (ctx);
 }
 
+void
+rsvg_drawing_ctx_increase_num_elements_acquired (RsvgDrawingCtx *draw_ctx)
+{
+    draw_ctx->num_elements_acquired++;
+}
+
+static gboolean
+limits_exceeded (RsvgDrawingCtx *draw_ctx)
+{
+    return draw_ctx->num_elements_acquired > 500000;
+}
+
 /*
  * rsvg_drawing_ctx_acquire_node:
  * @ctx: The drawing context in use
@@ -1668,6 +1680,10 @@ rsvg_drawing_ctx_acquire_node (RsvgDrawingCtx * ctx, const char *url)
   if (url == NULL)
       return NULL;
 
+  rsvg_drawing_ctx_increase_num_elements_acquired (ctx);
+  if (limits_exceeded (ctx))
+      return NULL;
+
   node = rsvg_defs_lookup (ctx->defs, url);
   if (node == NULL)
     return NULL;
@@ -1740,12 +1756,6 @@ rsvg_drawing_ctx_release_node (RsvgDrawingCtx * ctx, RsvgNode *node)
   ctx->acquired_nodes = g_slist_remove (ctx->acquired_nodes, node);
 }
 
-void
-rsvg_drawing_ctx_increase_num_elements_acquired (RsvgDrawingCtx *draw_ctx)
-{
-    draw_ctx->num_elements_acquired++;
-}
-
 void
 rsvg_drawing_ctx_add_node_and_ancestors_to_stack (RsvgDrawingCtx *draw_ctx, RsvgNode *node)
 {
@@ -1759,12 +1769,6 @@ rsvg_drawing_ctx_add_node_and_ancestors_to_stack (RsvgDrawingCtx *draw_ctx, Rsvg
     }
 }
 
-static gboolean
-limits_exceeded (RsvgDrawingCtx *draw_ctx)
-{
-    return draw_ctx->num_elements_acquired > 500000;
-}
-
 gboolean
 rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx, RsvgNode *node, int dominate)
 {


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