<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[186541] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/186541">186541</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-07-08 16:56:58 -0700 (Wed, 08 Jul 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Crash when appending an SVG <use> element dynamically which has animated SVG <path> element
https://bugs.webkit.org/show_bug.cgi?id=146690
<rdar://problem/20790376>
Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-07-08
Reviewed by Dean Jackson.
Source/WebCore:
Test: svg/animations/insert-animate-use-path-while-animation.svg
The crashing call stack shows that
SVGAnimatedListPropertyTearOff<SVGPathSegList>::m_animVal is null when
trying to access it in synchronizeWrappersIfNeeded(). This happens because
animationStarted() was not called for this animatedType.
SVGAnimateElementBase::resetAnimatedType() calls
SVGAnimatedPathAnimator::startAnimValAnimation() at the beginning of the
animation. For the target element and all its instances, this function calls
SVGAnimatedPathSegListPropertyTearOff::animationStarted() which calls
SVGAnimatedListPropertyTearOff<SVGPathSegList>::animationStarted(). This
last function allocates the member m_animVal when calling
SVGAnimatedListPropertyTearOff<SVGPathSegList>::animVal().
When adding a new instance of the same animating target element,
SVGAnimateElementBase::resetAnimatedType() just keeps calling
SVGAnimatedPathAnimator::animValDidChange() for all the instances of the
targetElement without ensuring that all of them have started their
animations.
The fix is to make SVGAnimatedPathAnimator::resetAnimValToBaseVal() ensure
that animationStarted() is called for the targetElement and all its instances.
* svg/SVGAnimatedPath.cpp:
(WebCore::SVGAnimatedPathAnimator::startAnimValAnimation): Move resetting
the animation value and starting the animatedTypes code to a new overriding
function which is named resetAnimValToBaseVal().
(WebCore::SVGAnimatedPathAnimator::resetAnimValToBaseVal): Call the overriding
function which calls buildSVGPathByteStreamFromSVGPathSegList() as before
and ensure that all the animatedTypes have started their animations.
* svg/SVGAnimatedPath.h:
LayoutTests:
When adding dynamically a new <use> element which references an animated
SVG path after the animation starts, ensure that WebKit is not crashing.
* svg/animations/insert-animate-use-path-while-animation-expected.txt: Added.
* svg/animations/insert-animate-use-path-while-animation.svg: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoresvgSVGAnimatedPathcpp">trunk/Source/WebCore/svg/SVGAnimatedPath.cpp</a></li>
<li><a href="#trunkSourceWebCoresvgSVGAnimatedPathh">trunk/Source/WebCore/svg/SVGAnimatedPath.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestssvganimationsinsertanimateusepathwhileanimationexpectedtxt">trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation-expected.txt</a></li>
<li><a href="#trunkLayoutTestssvganimationsinsertanimateusepathwhileanimationsvg">trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation.svg</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (186540 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-07-08 23:54:17 UTC (rev 186540)
+++ trunk/LayoutTests/ChangeLog        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-07-08 Said Abou-Hallawa <sabouhallawa@apple.com>
+
+ Crash when appending an SVG <use> element dynamically which has animated SVG <path> element
+ https://bugs.webkit.org/show_bug.cgi?id=146690
+ <rdar://problem/20790376>
+
+ Reviewed by Dean Jackson.
+
+ When adding dynamically a new <use> element which references an animated
+ SVG path after the animation starts, ensure that WebKit is not crashing.
+
+ * svg/animations/insert-animate-use-path-while-animation-expected.txt: Added.
+ * svg/animations/insert-animate-use-path-while-animation.svg: Added.
+
</ins><span class="cx"> 2015-07-08 David Kilzer <ddkilzer@apple.com>
</span><span class="cx">
</span><span class="cx"> http/tests/xmlviewer/dumpAsText/svg.xml contains a typo that breaks the test with libxml2 v2.9.2
</span></span></pre></div>
<a id="trunkLayoutTestssvganimationsinsertanimateusepathwhileanimationexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation-expected.txt (0 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation-expected.txt         (rev 0)
+++ trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation-expected.txt        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+Passed
</ins></span></pre></div>
<a id="trunkLayoutTestssvganimationsinsertanimateusepathwhileanimationsvg"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation.svg (0 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation.svg         (rev 0)
+++ trunk/LayoutTests/svg/animations/insert-animate-use-path-while-animation.svg        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+<svg width="600" height="400" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <path id="animatedRect" fill="green">
+ <animate
+ attributeType="XML"
+ attributeName="d"
+ from="M20 60 L20 110 L120 110 L120 60 Z"
+ to="M45 35 L45 135 L95 135 L95 35 Z"
+ dur="1s"
+ repeatCount="indefinite"/>
+ </path>
+ <script><![CDATA[
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ // Wait until the only instance of 'animatedRect' starts animation.
+ setTimeout(function () {
+ var svgns = 'http://www.w3.org/2000/svg';
+ var xlinkns = 'http://www.w3.org/1999/xlink';
+
+ for (var i = 1; i <= 4; i++) {
+ var shape = document.createElementNS(svgns, "use");
+ shape.setAttributeNS(xlinkns, 'href', '#animatedRect');
+ shape.setAttributeNS(null, 'transform', 'translate(' + 100 * i + ', 0)');
+ document.documentElement.appendChild(shape);
+ }
+
+ if (window.testRunner) {
+ // Wait until the next animation cycle starts to make sure
+ // all of the instances of 'animatedRect' are animating.
+ setTimeout(function () {
+ var text = document.createElementNS(svgns, "text");
+ text.appendChild(document.createTextNode("Passed"));
+ document.documentElement.appendChild(text);
+ testRunner.notifyDone();
+ }, 50);
+ }
+ }, 50);
+ ]]></script>
+</svg>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (186540 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-07-08 23:54:17 UTC (rev 186540)
+++ trunk/Source/WebCore/ChangeLog        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2015-07-08 Said Abou-Hallawa <sabouhallawa@apple.com>
+
+ Crash when appending an SVG <use> element dynamically which has animated SVG <path> element
+ https://bugs.webkit.org/show_bug.cgi?id=146690
+ <rdar://problem/20790376>
+
+ Reviewed by Dean Jackson.
+
+ Test: svg/animations/insert-animate-use-path-while-animation.svg
+
+ The crashing call stack shows that
+ SVGAnimatedListPropertyTearOff<SVGPathSegList>::m_animVal is null when
+ trying to access it in synchronizeWrappersIfNeeded(). This happens because
+ animationStarted() was not called for this animatedType.
+
+ SVGAnimateElementBase::resetAnimatedType() calls
+ SVGAnimatedPathAnimator::startAnimValAnimation() at the beginning of the
+ animation. For the target element and all its instances, this function calls
+ SVGAnimatedPathSegListPropertyTearOff::animationStarted() which calls
+ SVGAnimatedListPropertyTearOff<SVGPathSegList>::animationStarted(). This
+ last function allocates the member m_animVal when calling
+ SVGAnimatedListPropertyTearOff<SVGPathSegList>::animVal().
+
+ When adding a new instance of the same animating target element,
+ SVGAnimateElementBase::resetAnimatedType() just keeps calling
+ SVGAnimatedPathAnimator::animValDidChange() for all the instances of the
+ targetElement without ensuring that all of them have started their
+ animations.
+
+ The fix is to make SVGAnimatedPathAnimator::resetAnimValToBaseVal() ensure
+ that animationStarted() is called for the targetElement and all its instances.
+
+ * svg/SVGAnimatedPath.cpp:
+ (WebCore::SVGAnimatedPathAnimator::startAnimValAnimation): Move resetting
+ the animation value and starting the animatedTypes code to a new overriding
+ function which is named resetAnimValToBaseVal().
+
+ (WebCore::SVGAnimatedPathAnimator::resetAnimValToBaseVal): Call the overriding
+ function which calls buildSVGPathByteStreamFromSVGPathSegList() as before
+ and ensure that all the animatedTypes have started their animations.
+
+ * svg/SVGAnimatedPath.h:
+
</ins><span class="cx"> 2015-07-08 Brady Eidson <beidson@apple.com>
</span><span class="cx">
</span><span class="cx"> Move PingLoaders to the NetworkingProcess.
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGAnimatedPathcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGAnimatedPath.cpp (186540 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGAnimatedPath.cpp        2015-07-08 23:54:17 UTC (rev 186540)
+++ trunk/Source/WebCore/svg/SVGAnimatedPath.cpp        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -41,23 +41,10 @@
</span><span class="cx"> std::unique_ptr<SVGAnimatedType> SVGAnimatedPathAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(animatedTypes.size() >= 1);
</span><del>- SVGAnimatedPathSegListPropertyTearOff* property = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes[0].properties[0].get());
- const SVGPathSegList& baseValue = property->currentBaseValue();
</del><span class="cx">
</span><span class="cx"> // Build initial path byte stream.
</span><span class="cx"> auto byteStream = std::make_unique<SVGPathByteStream>();
</span><del>- buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream.get(), UnalteredParsing);
-
- Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result;
-
- for (auto& type : animatedTypes)
- result.append(castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(type.properties[0].get()));
-
- SVGElement::InstanceUpdateBlocker blocker(*property->contextElement());
-
- for (auto& segment : result)
- segment->animationStarted(byteStream.get(), &baseValue);
-
</del><ins>+ resetAnimValToBaseVal(animatedTypes, byteStream.get());
</ins><span class="cx"> return SVGAnimatedType::createPath(WTF::move(byteStream));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -66,13 +53,35 @@
</span><span class="cx"> stopAnimValAnimationForType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void SVGAnimatedPathAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGPathByteStream* byteStream)
+{
+ SVGAnimatedPathSegListPropertyTearOff* property = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes[0].properties[0].get());
+ const SVGPathSegList& baseValue = property->currentBaseValue();
+
+ buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream, UnalteredParsing);
+
+ Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result;
+
+ for (auto& type : animatedTypes) {
+ auto* segment = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(type.properties[0].get());
+ if (segment->isAnimating())
+ continue;
+ result.append(segment);
+ }
+
+ if (!result.isEmpty()) {
+ SVGElement::InstanceUpdateBlocker blocker(*property->contextElement());
+ for (auto& segment : result)
+ segment->animationStarted(byteStream, &baseValue);
+ }
+}
+
</ins><span class="cx"> void SVGAnimatedPathAnimator::resetAnimValToBaseVal(const SVGElementAnimatedPropertyList& animatedTypes, SVGAnimatedType* type)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(animatedTypes.size() >= 1);
</span><span class="cx"> ASSERT(type);
</span><span class="cx"> ASSERT(type->type() == m_type);
</span><del>- const SVGPathSegList& baseValue = castAnimatedPropertyToActualType<SVGAnimatedPathSegListPropertyTearOff>(animatedTypes[0].properties[0].get())->currentBaseValue();
- buildSVGPathByteStreamFromSVGPathSegList(baseValue, type->path(), UnalteredParsing);
</del><ins>+ resetAnimValToBaseVal(animatedTypes, type->path());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void SVGAnimatedPathAnimator::animValWillChange(const SVGElementAnimatedPropertyList& animatedTypes)
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGAnimatedPathh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGAnimatedPath.h (186540 => 186541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGAnimatedPath.h        2015-07-08 23:54:17 UTC (rev 186540)
+++ trunk/Source/WebCore/svg/SVGAnimatedPath.h        2015-07-08 23:56:58 UTC (rev 186541)
</span><span class="lines">@@ -40,6 +40,9 @@
</span><span class="cx"> virtual void addAnimatedTypes(SVGAnimatedType*, SVGAnimatedType*) override;
</span><span class="cx"> virtual void calculateAnimatedValue(float percentage, unsigned repeatCount, SVGAnimatedType*, SVGAnimatedType*, SVGAnimatedType*, SVGAnimatedType*) override;
</span><span class="cx"> virtual float calculateDistance(const String& fromString, const String& toString) override;
</span><ins>+
+private:
+ void resetAnimValToBaseVal(const SVGElementAnimatedPropertyList&, SVGPathByteStream*);
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>
</body>
</html>