[librsvg: 4/16] Do the limits check in acquire_node()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/16] Do the limits check in acquire_node()
- Date: Fri, 11 Oct 2019 23:42:45 +0000 (UTC)
commit d0cbdbf59da582a4b0ae9142001b56779306ad9b
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Oct 10 15:46:22 2019 -0500
Do the limits check in acquire_node()
This lets us remove the single-purpose
increase_num_elements_rendered_through_use().
rsvg_internals/src/drawing_ctx.rs | 24 +++++++++---------------
rsvg_internals/src/structure.rs | 2 --
2 files changed, 9 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index ec8f4db2..51b44a77 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -337,10 +337,16 @@ impl DrawingCtx {
// acquire it again. If you acquire a node "#foo" and don't release it before
// trying to acquire "foo" again, you will obtain a None the second time.
pub fn acquire_node(
- &self,
+ &mut self,
fragment: &Fragment,
node_types: &[NodeType]
) -> Result<AcquiredNode, AcquireError> {
+ self.num_elements_acquired += 1;
+
+ if self.num_elements_acquired > limits::MAX_REFERENCED_ELEMENTS {
+ return Err(AcquireError::MaxReferencesExceeded);
+ }
+
self.acquired_nodes.acquire(fragment, node_types)
}
@@ -612,7 +618,7 @@ impl DrawingCtx {
);
}
- fn acquire_paint_server(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
+ fn acquire_paint_server(&mut self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
self.acquire_node(
fragment,
&[
@@ -857,7 +863,7 @@ impl DrawingCtx {
self.drawsub_stack.push(top);
}
- res.and_then(|bbox| self.check_limits().and_then(|_| Ok(bbox)))
+ res
}
pub fn add_node_and_ancestors_to_stack(&mut self, node: &RsvgNode) {
@@ -866,18 +872,6 @@ impl DrawingCtx {
self.add_node_and_ancestors_to_stack(parent);
}
}
-
- pub fn increase_num_elements_rendered_through_use(&mut self, n: usize) {
- self.num_elements_acquired += n;
- }
-
- fn check_limits(&self) -> Result<(), RenderingError> {
- if self.num_elements_acquired > limits::MAX_REFERENCED_ELEMENTS {
- Err(RenderingError::InstancingLimit)
- } else {
- Ok(())
- }
- }
}
#[derive(Debug)]
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 8771100d..de27c194 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -330,8 +330,6 @@ impl NodeTrait for NodeUse {
return Err(RenderingError::CircularReference);
}
- draw_ctx.increase_num_elements_rendered_through_use(1);
-
let params = draw_ctx.get_view_params();
let nx = self.x.normalize(values, ¶ms);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]