- Revision
- 190966
- Author
- [email protected]
- Date
- 2015-10-13 04:03:20 -0700 (Tue, 13 Oct 2015)
Log Message
Merge r190634 - Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange()
https://bugs.webkit.org/show_bug.cgi?id=149300
<rdar://problem/22747046>
Patch by Jiewen Tan <[email protected]> on 2015-10-06
Reviewed by Chris Dumez.
Source/WebCore:
This is a merge of Blink r167845 and r194944:
https://codereview.chromium.org/177093016
https://codereview.chromium.org/1124863003
Test: editing/style/apply-style-crash2.html
editing/style/apply-style-crash3.html
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
The issue was that we would traverse the DOM tree past the beyondEnd
under some circumstances and thus NodeTraversal::next() would return
null unexpectedly. This CL adds a check to make sure startNode != beyondEnd
before traversing to avoid the problem.
Besides that, this CL hardens changing font style over unknown elements.
When adjusting the start node position of where to apply a font style
command, check that we haven't stepped off the end.
This CL also adds a few more assertions to catch similar issues
more easily in the future.
LayoutTests:
* editing/style/apply-style-crash2-expected.txt: Added.
* editing/style/apply-style-crash2.html: Added.
* editing/style/apply-style-crash3-expected.txt: Added.
* editing/style/apply-style-crash3.html: Added.
Modified Paths
Added Paths
Diff
Modified: releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog (190965 => 190966)
--- releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog 2015-10-13 11:02:05 UTC (rev 190965)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/ChangeLog 2015-10-13 11:03:20 UTC (rev 190966)
@@ -1,3 +1,16 @@
+2015-10-06 Jiewen Tan <[email protected]>
+
+ Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange()
+ https://bugs.webkit.org/show_bug.cgi?id=149300
+ <rdar://problem/22747046>
+
+ Reviewed by Chris Dumez.
+
+ * editing/style/apply-style-crash2-expected.txt: Added.
+ * editing/style/apply-style-crash2.html: Added.
+ * editing/style/apply-style-crash3-expected.txt: Added.
+ * editing/style/apply-style-crash3.html: Added.
+
2015-10-05 Chris Dumez <[email protected]>
data: URLs should not be preloaded
Added: releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2-expected.txt (0 => 190966)
--- releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2-expected.txt (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2-expected.txt 2015-10-13 11:03:20 UTC (rev 190966)
@@ -0,0 +1,2 @@
+This test passes if it does not crash.
+PASS
Added: releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2.html (0 => 190966)
--- releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2.html (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash2.html 2015-10-13 11:03:20 UTC (rev 190966)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+This test passes if it does not crash.
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+el1 = document.createElement('li');
+document.body.appendChild(el1);
+el2 = document.createElement('thead');
+el1.appendChild(el2);
+el2.parentNode.insertBefore(document.createElement('video'), el2);
+el2.parentNode.insertBefore(document.createElement('input'), el2);
+document.designMode = 'on';
+window.getSelection().setBaseAndExtent(el1, 2, el2, 4);
+document.designMode = 'off';
+window.getSelection().modify('extend', 'backward', 'character');
+el1.innerHTML = "PASS";
+document.designMode = 'on';
+document.execCommand('FontSizeDelta', false, '-1px');
+document.designMode = 'off';
+</script>
+</body>
+</html>
Added: releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash3-expected.txt (0 => 190966)
--- releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash3-expected.txt (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash3-expected.txt 2015-10-13 11:03:20 UTC (rev 190966)
@@ -0,0 +1,9 @@
+Verify that changing the style over an unknown element 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.10/LayoutTests/editing/style/apply-style-crash3.html (0 => 190966)
--- releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash3.html (rev 0)
+++ releases/WebKitGTK/webkit-2.10/LayoutTests/editing/style/apply-style-crash3.html 2015-10-13 11:03:20 UTC (rev 190966)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<unknown>
+<script></script>
+<textarea></textarea>
+<script>
+function onDOMNodeRemoved(e) {
+ if (!(e.srcElement instanceof Element))
+ return;
+
+ e.srcElement.insertAdjacentHTML('afterbegin', ' ');
+ document.execCommand('FontSizeDelta', false, '1px');
+}
+
+document.addEventListener("DOMNodeRemoved", onDOMNodeRemoved, false);
+document.designMode = "on";
+document.execCommand("SelectAll", false)
+var unknown = document.getElementsByTagName("unknown")[0];
+unknown.textContent = "sss";
+unknown.outerHTML = "";
+document.execCommand("SelectAll", false);
+// Put description() here so as to not upset test condition.
+description("Verify that changing the style over an unknown element does not crash.");
+</script>
+</body>
+</html>
Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog (190965 => 190966)
--- releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog 2015-10-13 11:02:05 UTC (rev 190965)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog 2015-10-13 11:03:20 UTC (rev 190966)
@@ -1,3 +1,32 @@
+2015-10-06 Jiewen Tan <[email protected]>
+
+ Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange()
+ https://bugs.webkit.org/show_bug.cgi?id=149300
+ <rdar://problem/22747046>
+
+ Reviewed by Chris Dumez.
+
+ This is a merge of Blink r167845 and r194944:
+ https://codereview.chromium.org/177093016
+ https://codereview.chromium.org/1124863003
+
+ Test: editing/style/apply-style-crash2.html
+ editing/style/apply-style-crash3.html
+
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
+ The issue was that we would traverse the DOM tree past the beyondEnd
+ under some circumstances and thus NodeTraversal::next() would return
+ null unexpectedly. This CL adds a check to make sure startNode != beyondEnd
+ before traversing to avoid the problem.
+
+ Besides that, this CL hardens changing font style over unknown elements.
+ When adjusting the start node position of where to apply a font style
+ command, check that we haven't stepped off the end.
+
+ This CL also adds a few more assertions to catch similar issues
+ more easily in the future.
+
2015-10-06 Zalan Bujtas <[email protected]>
Remove redundant isComposited() function and replace
Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/editing/ApplyStyleCommand.cpp (190965 => 190966)
--- releases/WebKitGTK/webkit-2.10/Source/WebCore/editing/ApplyStyleCommand.cpp 2015-10-13 11:02:05 UTC (rev 190965)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/editing/ApplyStyleCommand.cpp 2015-10-13 11:03:20 UTC (rev 190966)
@@ -348,7 +348,9 @@
// Calculate loop end point.
// If the end node is before the start node (can only happen if the end node is
// an ancestor of the start node), we gather nodes up to the next sibling of the end node
- Node *beyondEnd;
+ Node* beyondEnd;
+ ASSERT(start.deprecatedNode());
+ ASSERT(end.deprecatedNode());
if (start.deprecatedNode()->isDescendantOf(end.deprecatedNode()))
beyondEnd = NodeTraversal::nextSkippingChildren(*end.deprecatedNode());
else
@@ -356,20 +358,33 @@
start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
Node* startNode = start.deprecatedNode();
- if (startNode->isTextNode() && start.deprecatedEditingOffset() >= caretMaxOffset(startNode)) // Move out of text node if range does not include its characters.
+
+ // Make sure we're not already at the end or the next NodeTraversal::next() will traverse
+ // past it.
+ if (startNode == beyondEnd)
+ return;
+
+ if (startNode->isTextNode() && start.deprecatedEditingOffset() >= caretMaxOffset(startNode)) {
+ // Move out of text node if range does not include its characters.
startNode = NodeTraversal::next(*startNode);
+ if (!startNode)
+ return;
+ }
// Store away font size before making any changes to the document.
// This ensures that changes to one node won't effect another.
HashMap<Node*, float> startingFontSizes;
- for (Node *node = startNode; node != beyondEnd; node = NodeTraversal::next(*node))
+ for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
+ ASSERT(node);
startingFontSizes.set(node, computedFontSize(node));
+ }
// These spans were added by us. If empty after font size changes, they can be removed.
Vector<RefPtr<HTMLElement>> unstyledSpans;
- Node* lastStyledNode = 0;
+ Node* lastStyledNode = nullptr;
for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
+ ASSERT(node);
RefPtr<HTMLElement> element;
if (is<HTMLElement>(*node)) {
// Only work on fully selected nodes.