Title: [197125] trunk/Source/WebCore
Revision
197125
Author
s...@apple.com
Date
2016-02-25 11:55:55 -0800 (Thu, 25 Feb 2016)

Log Message

REGRESSION (r196268): Many assertion failures and crashes on SVG path animation tests when JS garbage collection happens quickly
https://bugs.webkit.org/show_bug.cgi?id=154331

Reviewed by Darin Adler.

This is not an actual regression. The bug did exist before r196268 but
the whole document was leaking once an SVGAnimatedProperty was created
so there was no way to produce this bug. After fixing the leak, one crash
and one assert got uncovered. Both of them happen because of the fact:
"if an SVGAnimatedProperty is not referenced it will be deleted."

* svg/SVGPathElement.cpp:
(WebCore::SVGPathElement::lookupOrCreateDWrapper):
The code in this function was assuming that the wrapper will be created
only once which happens when SVGAnimatedProperty::lookupOrCreateWrapper()
is called. Before making this single call, lookupOrCreateDWrapper() was
building an initial SVGPathSegList from byte stream. But now
SVGAnimatedProperty::lookupWrapper() can return false even after creating
the SVGAnimatedProperty because it was deleted later. Calling
buildSVGPathSegListFromByteStream() more than once was causing
SVGAnimatedListPropertyTearOff::animationStarted() to fire the assertion
ASSERT(m_values.size() == m_wrappers.size()) because the path segments were
appended twice to m_values which is in fact SVGPathElement::m_pathSegList.value.
The fix is to build the initial SVGPathSegList only once which should happen
when m_pathSegList.value.isEmpty().
        
(WebCore::SVGPathElement::animatedPropertyWillBeDeleted):
* svg/SVGPathElement.h:
* svg/properties/SVGAnimatedPathSegListPropertyTearOff.h:
(WebCore::SVGAnimatedPathSegListPropertyTearOff::~SVGAnimatedPathSegListPropertyTearOff):
SVGPathElement is assuming the following equivalence relation:
m_pathSegList.shouldSynchronize ~ SVGAnimatedProperty_is_created_and_not_null.
SVGPathElement::animatedPathSegList() and animatedNormalizedPathSegList()
set m_pathSegList.shouldSynchronize to true when SVGAnimatedProperty is
created but nothing sets m_pathSegList.shouldSynchronize back to false.
This was not a problem when the SVGAnimatedProperty was leaking but after
ensuring it is deleted when it is not referenced this equivalence relation
becomes untrue sometimes. This caused SVGPathElement::svgAttributeChanged()
to crash when we check m_pathSegList.shouldSynchronize and if it is true we
assume that SVGAnimatedProperty::lookupWrapper() will return a non-null pointer
and therefore we deference this pointer and call SVGAnimatedProperty::isAnimating().
To fix this crash we need to set m_pathSegList.shouldSynchronize back to false
when the associated SVGAnimatedProperty is deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197124 => 197125)


--- trunk/Source/WebCore/ChangeLog	2016-02-25 19:36:52 UTC (rev 197124)
+++ trunk/Source/WebCore/ChangeLog	2016-02-25 19:55:55 UTC (rev 197125)
@@ -1,3 +1,49 @@
+2016-02-25  Said Abou-Hallawa  <sabouhall...@apple.com>
+
+        REGRESSION (r196268): Many assertion failures and crashes on SVG path animation tests when JS garbage collection happens quickly
+        https://bugs.webkit.org/show_bug.cgi?id=154331
+
+        Reviewed by Darin Adler.
+
+        This is not an actual regression. The bug did exist before r196268 but
+        the whole document was leaking once an SVGAnimatedProperty was created
+        so there was no way to produce this bug. After fixing the leak, one crash
+        and one assert got uncovered. Both of them happen because of the fact:
+        "if an SVGAnimatedProperty is not referenced it will be deleted."
+
+        * svg/SVGPathElement.cpp:
+        (WebCore::SVGPathElement::lookupOrCreateDWrapper):
+        The code in this function was assuming that the wrapper will be created
+        only once which happens when SVGAnimatedProperty::lookupOrCreateWrapper()
+        is called. Before making this single call, lookupOrCreateDWrapper() was
+        building an initial SVGPathSegList from byte stream. But now
+        SVGAnimatedProperty::lookupWrapper() can return false even after creating
+        the SVGAnimatedProperty because it was deleted later. Calling
+        buildSVGPathSegListFromByteStream() more than once was causing
+        SVGAnimatedListPropertyTearOff::animationStarted() to fire the assertion
+        ASSERT(m_values.size() == m_wrappers.size()) because the path segments were
+        appended twice to m_values which is in fact SVGPathElement::m_pathSegList.value.
+        The fix is to build the initial SVGPathSegList only once which should happen
+        when m_pathSegList.value.isEmpty().
+        
+        (WebCore::SVGPathElement::animatedPropertyWillBeDeleted):
+        * svg/SVGPathElement.h:
+        * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h:
+        (WebCore::SVGAnimatedPathSegListPropertyTearOff::~SVGAnimatedPathSegListPropertyTearOff):
+        SVGPathElement is assuming the following equivalence relation:
+        m_pathSegList.shouldSynchronize ~ SVGAnimatedProperty_is_created_and_not_null.
+        SVGPathElement::animatedPathSegList() and animatedNormalizedPathSegList()
+        set m_pathSegList.shouldSynchronize to true when SVGAnimatedProperty is
+        created but nothing sets m_pathSegList.shouldSynchronize back to false.
+        This was not a problem when the SVGAnimatedProperty was leaking but after
+        ensuring it is deleted when it is not referenced this equivalence relation
+        becomes untrue sometimes. This caused SVGPathElement::svgAttributeChanged()
+        to crash when we check m_pathSegList.shouldSynchronize and if it is true we
+        assume that SVGAnimatedProperty::lookupWrapper() will return a non-null pointer
+        and therefore we deference this pointer and call SVGAnimatedProperty::isAnimating().
+        To fix this crash we need to set m_pathSegList.shouldSynchronize back to false
+        when the associated SVGAnimatedProperty is deleted.
+
 2016-02-25  Brady Eidson  <beid...@apple.com>
 
         Modern IDB: WebKit 2 IPC layer.

Modified: trunk/Source/WebCore/svg/SVGPathElement.cpp (197124 => 197125)


--- trunk/Source/WebCore/svg/SVGPathElement.cpp	2016-02-25 19:36:52 UTC (rev 197124)
+++ trunk/Source/WebCore/svg/SVGPathElement.cpp	2016-02-25 19:55:55 UTC (rev 197125)
@@ -313,8 +313,8 @@
     if (auto property = SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(&ownerType, dPropertyInfo()))
         return *property;
 
-    // Build initial SVGPathSegList.
-    buildSVGPathSegListFromByteStream(ownerType.m_pathByteStream, ownerType, ownerType.m_pathSegList.value, UnalteredParsing);
+    if (ownerType.m_pathSegList.value.isEmpty())
+        buildSVGPathSegListFromByteStream(ownerType.m_pathByteStream, ownerType, ownerType.m_pathSegList.value, UnalteredParsing);
 
     return SVGAnimatedProperty::lookupOrCreateWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff, SVGPathSegList>
         (&ownerType, dPropertyInfo(), ownerType.m_pathSegList.value);
@@ -329,6 +329,15 @@
     ownerType.m_pathSegList.synchronize(&ownerType, dPropertyInfo()->attributeName, ownerType.m_pathSegList.value.valueAsString());
 }
 
+void SVGPathElement::animatedPropertyWillBeDeleted()
+{
+    // m_pathSegList.shouldSynchronize is set to true when the 'd' wrapper for m_pathSegList
+    // is created and cached. We need to reset it back to false when this wrapper is deleted
+    // so we can be sure if shouldSynchronize is true, SVGAnimatedProperty::lookupWrapper()
+    // will return a valid cached 'd' wrapper for the m_pathSegList.
+    m_pathSegList.shouldSynchronize = false;
+}
+
 RefPtr<SVGPathSegListPropertyTearOff> SVGPathElement::pathSegList()
 {
     m_pathSegList.shouldSynchronize = true;

Modified: trunk/Source/WebCore/svg/SVGPathElement.h (197124 => 197125)


--- trunk/Source/WebCore/svg/SVGPathElement.h	2016-02-25 19:36:52 UTC (rev 197124)
+++ trunk/Source/WebCore/svg/SVGPathElement.h	2016-02-25 19:55:55 UTC (rev 197125)
@@ -99,6 +99,8 @@
 
     WeakPtr<SVGPathElement> createWeakPtr() const { return m_weakPtrFactory.createWeakPtr(); }
 
+    void animatedPropertyWillBeDeleted();
+
 private:
     SVGPathElement(const QualifiedName&, Document&);
 

Modified: trunk/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h (197124 => 197125)


--- trunk/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h	2016-02-25 19:36:52 UTC (rev 197124)
+++ trunk/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h	2016-02-25 19:55:55 UTC (rev 197125)
@@ -112,8 +112,15 @@
         : SVGAnimatedListPropertyTearOff<SVGPathSegList>(contextElement, attributeName, animatedPropertyType, values)
         , m_animatedPathByteStream(nullptr)
     {
+        ASSERT(contextElement);
+        ASSERT(is<SVGPathElement>(contextElement));
     }
 
+    virtual ~SVGAnimatedPathSegListPropertyTearOff()
+    {
+        downcast<SVGPathElement>(contextElement())->animatedPropertyWillBeDeleted();
+    }
+
     SVGPathByteStream* m_animatedPathByteStream;
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to