Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Nested use of same SVG resource fails
https://bugs.webkit.org/show_bug.cgi?id=130127

Reviewed by Said Abou-Hallawa.

Merge https://src.chromium.org/viewvc/blink?view=revision&revision=175129

* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-1-expected.txt: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-1.html: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-2-expected.txt: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-2.html: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-3-expected.txt: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-3.html: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-4-expected.txt: Added.
* LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-4.html: Added.
* LayoutTests/svg/custom/pattern-directly-and-indirectly-referenced-expected.svg: Added.
* LayoutTests/svg/custom/pattern-directly-and-indirectly-referenced.svg: Added.
* LayoutTests/svg/custom/pattern-false-resource-cycle-expected.html: Added.
* LayoutTests/svg/custom/pattern-false-resource-cycle.html: Added.
* LayoutTests/svg/custom/pattern-within-other-pattern-expected.html: Added.
* LayoutTests/svg/custom/pattern-within-other-pattern.html: Added.
* Source/WebCore/rendering/svg/SVGResourcesCycleSolver.cpp:
(WebCore::SVGResourcesCycleSolver::SVGResourcesCycleSolver): Deleted.
(WebCore::SVGResourcesCycleSolver::resourceContainsCycles):
(WebCore::SVGResourcesCycleSolver::resolveCycles):
(WebCore::SVGResourcesCycleSolver::breakCycle):
* Source/WebCore/rendering/svg/SVGResourcesCycleSolver.h:
(WebCore::SVGResourcesCycleSolver::SVGResourcesCycleSolver):

Canonical link: https://commits.webkit.org/264618@main
  • Loading branch information
rniwa committed May 27, 2023
1 parent a59adcc commit 99265dc
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 158 deletions.
@@ -0,0 +1,3 @@
PASS if no crash (stack overflow).


32 changes: 32 additions & 0 deletions LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-1.html
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
window.onload = function() {
testRunner.display();
mutateTree();
testRunner.display();
testRunner.notifyDone();
};
} else {
window.onload = function() { setTimeout(mutateTree, 100); };
}
function mutateTree() {
// A reference from the 'rect' to the pattern cycle.
document.getElementsByTagName('rect')[0].setAttribute('fill', 'url(#p1)');
}
</script>
<p>PASS if no crash (stack overflow).</p>
<svg width="100" height="100">
<rect width="100" height="100"/>
<pattern id="p3" width="1" height="1">
<rect fill="url(#p1)" width="100" height="100"/>
</pattern>
<pattern id="p2" width="1" height="1">
<rect fill="url(#p3)" width="100" height="100"/>
</pattern>
<pattern id="p1" width="1" height="1">
<rect fill="url(#p2)" width="100" height="100"/>
</pattern>
</svg>
@@ -0,0 +1,3 @@
PASS if no crash (stack overflow).


32 changes: 32 additions & 0 deletions LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-2.html
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
window.onload = function() {
testRunner.display();
mutateTree();
testRunner.display();
testRunner.notifyDone();
};
} else {
window.onload = function() { setTimeout(mutateTree, 100); };
}
function mutateTree() {
// Add a reference from the rect in pattern#p3 to form a cycle.
document.getElementsByTagName('rect')[1].setAttribute('fill', 'url(#p1)');
}
</script>
<p>PASS if no crash (stack overflow).</p>
<svg width="100" height="100">
<rect width="100" height="100" fill="url(#p1)"/>
<pattern id="p3" width="1" height="1">
<rect width="100" height="100"/>
</pattern>
<pattern id="p2" width="1" height="1">
<rect fill="url(#p3)" width="100" height="100"/>
</pattern>
<pattern id="p1" width="1" height="1">
<rect fill="url(#p2)" width="100" height="100"/>
</pattern>
</svg>
@@ -0,0 +1,3 @@
PASS if no crash (stack overflow).


40 changes: 40 additions & 0 deletions LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-3.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
window.onload = function() {
testRunner.display();
mutateTree();
testRunner.display();
testRunner.notifyDone();
};
} else {
window.onload = function() { setTimeout(mutateTree, 100); };
}
const svgNs = 'http://www.w3.org/2000/svg';
function buildPattern(patternId, refId) {
var pattern = document.createElementNS(svgNs, 'pattern');
var rect = pattern.appendChild(document.createElementNS(svgNs, 'rect'));
pattern.setAttribute('id', patternId);
pattern.setAttribute('width', 1);
pattern.setAttribute('height', 1);
rect.setAttribute('width', 100);
rect.setAttribute('height', 100);
rect.setAttribute('fill', 'url(#' + refId + ')');
return pattern;
}
function mutateTree() {
// Build a three-step pattern cycle in a detached
// subtree and then insert it at load.
var defs = document.createElementNS(svgNs, 'defs');
defs.appendChild(buildPattern('p3', 'p1'));
defs.appendChild(buildPattern('p2', 'p3'));
defs.appendChild(buildPattern('p1', 'p2'));
document.querySelector('svg').appendChild(defs);
}
</script>
<p>PASS if no crash (stack overflow).</p>
<svg width="100" height="100">
<rect width="100" height="100" fill="url(#p1)"/>
</svg>
@@ -0,0 +1,3 @@
PASS if no crash (stack overflow).


49 changes: 49 additions & 0 deletions LayoutTests/svg/custom/pattern-3-step-cycle-dynamic-4.html
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<script src="../../resources/run-after-display.js"></script>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
window.onload = function() {
testRunner.display();
mutateTree();
testRunner.display();
testRunner.notifyDone();
};
} else {
window.onload = function() { setTimeout(mutateTree, 100); };
}
const svgNs = 'http://www.w3.org/2000/svg';
function buildPattern(patternId, refId) {
var pattern = document.createElementNS(svgNs, 'pattern');
var rect = pattern.appendChild(document.createElementNS(svgNs, 'rect'));
pattern.setAttribute('id', patternId);
pattern.setAttribute('width', 1);
pattern.setAttribute('height', 1);
rect.setAttribute('width', 100);
rect.setAttribute('height', 100);
rect.setAttribute('fill', 'url(#' + refId + ')');
return pattern;
}
function mutateTree() {
// Get reference to rect in pattern#p2 before inserting the pattern.
var p2rect = document.getElementsByTagName('rect')[1];

// Add a pattern#p3 and a reference to it from pattern#p2 to form a cycle.
var defs = document.querySelector('defs');
defs.appendChild(buildPattern('p3', 'p1'));
p2rect.setAttribute('fill', 'url(#p3)');
}
</script>
<p>PASS if no crash (stack overflow).</p>
<svg width="100" height="100">
<rect width="100" height="100" fill="url(#p1)"/>
<defs>
<pattern id="p2" width="1" height="1">
<rect width="100" height="100"/>
</pattern>
<pattern id="p1" width="1" height="1">
<rect fill="url(#p2)" width="100" height="100"/>
</pattern>
</defs>
</svg>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions LayoutTests/svg/custom/pattern-false-resource-cycle-expected.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<svg>
<clipPath id="c1">
<rect width="100" height="100"/>
</clipPath>
<pattern id="p1" width="1" height="1">
<rect width="100" height="100" fill="green"/>
</pattern>
<rect width="100" height="100" fill="url(#p1)" clip-path="url(#c1)"/>
</svg>
13 changes: 13 additions & 0 deletions LayoutTests/svg/custom/pattern-false-resource-cycle.html
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<svg>
<clipPath id="c1">
<rect width="100" height="100"/>
</clipPath>
<pattern id="p1" width="1" height="1">
<rect width="100" height="100" fill="green"/>
<clipPath id="c2" clip-path="url(#c1)">
<rect width="100" height="100"/>
</clipPath>
</pattern>
<rect width="100" height="100" fill="url(#p1)" clip-path="url(#c1)"/>
</svg>
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<svg width="100" height="100">
<pattern id="p" width="1" height="1">
<rect width="100" height="100" fill="green"/>
</pattern>
<rect width="100" height="100" fill="url(#p)"/>
</svg>
10 changes: 10 additions & 0 deletions LayoutTests/svg/custom/pattern-within-other-pattern.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<svg width="100" height="100">
<pattern id="outer" width="1" height="1">
<pattern id="inner" width="1" height="1">
<rect width="100" height="100" fill="url(#outer)"/>
</pattern>
<rect width="100" height="100" fill="green"/>
</pattern>
<rect width="100" height="100" fill="url(#inner)"/>
</svg>
3 changes: 1 addition & 2 deletions Source/WebCore/rendering/svg/SVGResourcesCache.cpp
Expand Up @@ -45,8 +45,7 @@ void SVGResourcesCache::addResourcesFromRenderer(RenderElement& renderer, const
SVGResources& resources = *m_cache.add(&renderer, WTFMove(newResources)).iterator->value;

// Run cycle-detection _afterwards_, so self-references can be caught as well.
SVGResourcesCycleSolver solver(renderer, resources);
solver.resolveCycles();
SVGResourcesCycleSolver::resolveCycles(renderer, resources);

// Walk resources and register the render object at each resources.
WeakHashSet<RenderSVGResourceContainer> resourceSet;
Expand Down

0 comments on commit 99265dc

Please sign in to comment.