Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BATIK-1319] Prevent the use element from being called too many times. #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,28 @@ public class BridgeContext implements ErrorConstants, CSSContext {
*/
protected float animationLimitingAmount;

protected int useElementBridgeCalculationLimit = DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT;

public static final int DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT = 1024;

public int getUseElementBridgeCalculationLimit() {
return useElementBridgeCalculationLimit;
}

public void setUseElementBridgeCalculationLimit(int useElementBridgeCalculationLimit) {
this.useElementBridgeCalculationLimit = useElementBridgeCalculationLimit;
}

public boolean stopAfterConsumeUseElementBridgeCalculationLimit() {
int useElementBridgeCalculationLimit = this.getUseElementBridgeCalculationLimit();
if (useElementBridgeCalculationLimit <= 0) {
return true;
}
--useElementBridgeCalculationLimit;
this.setUseElementBridgeCalculationLimit(useElementBridgeCalculationLimit);
return false;
}

/**
* By default we share a unique instance of InterpreterPool.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
*/
public CompositeGraphicsNode buildCompositeGraphicsNode
(BridgeContext ctx, Element e, CompositeGraphicsNode gn) {

if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
return null;
}

// get the referenced element
SVGOMUseElement ue = (SVGOMUseElement) e;
String uri = ue.getHref().getAnimVal();
Expand Down Expand Up @@ -159,6 +164,9 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
for (Node n = localRefElement.getFirstChild();
n != null;
n = localRefElement.getFirstChild()) {
if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
return null;
}
svgElement.appendChild(n);
}
localRefElement = svgElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,17 @@ protected void configure(SVGConverter c){
addTest(t);
t.setId("OutputTest.reference");

t = new ConverterOutputTest("samples/manyuse.svg", // File to convert
"test-reports/manyuse.png", // Output
"test-references/samples/manyuse.png"); // reference
addTest(t);
t.setId("manyuse");

t = new ConverterOutputTest("samples/3points.svg", // File to convert
"test-reports/3points.png", // Output
"test-references/samples/3points.png"); // reference
addTest(t);
t.setId("3points");
}
}

Expand Down
5 changes: 5 additions & 0 deletions samples/3points.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.