Title: [197293] releases/WebKitGTK/webkit-2.4
Revision
197293
Author
[email protected]
Date
2016-02-28 06:56:04 -0800 (Sun, 28 Feb 2016)

Log Message

Merge r178363 - Element::normalizeAttributes() needs to handle arbitrary JS executing between loop iterations.
<https://webkit.org/b/140379>
<rdar://problem/19446901>

Reviewed by Benjamin Poulain.

Source/WebCore:

Since DOM mutation events may arise below the call to Node::normalize(),
have the loop in Element::normalizeAttributes() make a copy of the Attr nodes
beforehand, to guard against mutations.

Based on a patch by Chris "Chris Dumez" Dumez.

Test: fast/dom/Element/normalize-crash2.html

* dom/Element.cpp:
(WebCore::Element::normalizeAttributes):

LayoutTests:

* fast/dom/Element/normalize-crash2-expected.txt: Added.
* fast/dom/Element/normalize-crash2.html: Added.

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.4/LayoutTests/ChangeLog (197292 => 197293)


--- releases/WebKitGTK/webkit-2.4/LayoutTests/ChangeLog	2016-02-28 14:46:42 UTC (rev 197292)
+++ releases/WebKitGTK/webkit-2.4/LayoutTests/ChangeLog	2016-02-28 14:56:04 UTC (rev 197293)
@@ -1,3 +1,14 @@
+2015-01-13  Andreas Kling  <[email protected]>
+
+        Element::normalizeAttributes() needs to handle arbitrary JS executing between loop iterations.
+        <https://webkit.org/b/140379>
+        <rdar://problem/19446901>
+
+        Reviewed by Benjamin Poulain.
+
+        * fast/dom/Element/normalize-crash2-expected.txt: Added.
+        * fast/dom/Element/normalize-crash2.html: Added.
+
 2015-02-05  Maciej Stachowiak  <[email protected]>
 
         Crash due to failing to dirty a removed text node's line box

Added: releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2-expected.txt (0 => 197293)


--- releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2-expected.txt	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2-expected.txt	2016-02-28 14:56:04 UTC (rev 197293)
@@ -0,0 +1,9 @@
+This test passes if it does not crash.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2.html (0 => 197293)


--- releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.4/LayoutTests/fast/dom/Element/normalize-crash2.html	2016-02-28 14:56:04 UTC (rev 197293)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<script src=""
+<div name="testDiv" id="testDiv"></div>
+<script>
+description("This test passes if it does not crash.");
+ 
+var testDiv = document.getElementById("testDiv");
+testDiv.attributes[0].appendChild(new Text("test"));
+testDiv.cloneNode(false);
+gc();
+testDiv.normalize();
+</script>

Modified: releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog (197292 => 197293)


--- releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog	2016-02-28 14:46:42 UTC (rev 197292)
+++ releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog	2016-02-28 14:56:04 UTC (rev 197293)
@@ -1,3 +1,22 @@
+2015-01-13  Andreas Kling  <[email protected]>
+
+        Element::normalizeAttributes() needs to handle arbitrary JS executing between loop iterations.
+        <https://webkit.org/b/140379>
+        <rdar://problem/19446901>
+
+        Reviewed by Benjamin Poulain.
+
+        Since DOM mutation events may arise below the call to Node::normalize(),
+        have the loop in Element::normalizeAttributes() make a copy of the Attr nodes
+        beforehand, to guard against mutations.
+
+        Based on a patch by Chris "Chris Dumez" Dumez.
+
+        Test: fast/dom/Element/normalize-crash2.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::normalizeAttributes):
+
 2015-02-06  Maciej Stachowiak  <[email protected]>
 
         REGRESSION(r179706): Caused memory corruption on some tests (Requested by _ap_ on #webkit).

Modified: releases/WebKitGTK/webkit-2.4/Source/WebCore/dom/Element.cpp (197292 => 197293)


--- releases/WebKitGTK/webkit-2.4/Source/WebCore/dom/Element.cpp	2016-02-28 14:46:42 UTC (rev 197292)
+++ releases/WebKitGTK/webkit-2.4/Source/WebCore/dom/Element.cpp	2016-02-28 14:56:04 UTC (rev 197293)
@@ -2326,10 +2326,17 @@
 {
     if (!hasAttributes())
         return;
-    for (const Attribute& attribute : attributesIterator()) {
-        if (RefPtr<Attr> attr = attrIfExists(attribute.name()))
-            attr->normalize();
-    }
+
+    auto* attrNodeList = attrNodeListForElement(this);
+    if (!attrNodeList)
+        return;
+
+    // Copy the Attr Vector because Node::normalize() can fire synchronous JS
+    // events (e.g. DOMSubtreeModified) and a JS listener could add / remove
+    // attributes while we are iterating.
+    auto copyOfAttrNodeList = *attrNodeList;
+    for (auto& attrNode : copyOfAttrNodeList)
+        attrNode->normalize();
 }
 
 PseudoElement* Element::beforePseudoElement() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to