- Revision
- 190634
- Author
- commit-qu...@webkit.org
- Date
- 2015-10-06 12:48:24 -0700 (Tue, 06 Oct 2015)
Log Message
Fix crash in ApplyStyleCommand::applyRelativeFontStyleChange()
https://bugs.webkit.org/show_bug.cgi?id=149300
<rdar://problem/22747046>
Patch by Jiewen Tan <jiewen_...@apple.com> 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: trunk/LayoutTests/ChangeLog (190633 => 190634)
--- trunk/LayoutTests/ChangeLog 2015-10-06 19:23:52 UTC (rev 190633)
+++ trunk/LayoutTests/ChangeLog 2015-10-06 19:48:24 UTC (rev 190634)
@@ -1,3 +1,16 @@
+2015-10-06 Jiewen Tan <jiewen_...@apple.com>
+
+ 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-06 Javier Fernandez <jfernan...@igalia.com>
[CSS Grid Layout] Don't need to reset auto-margins during grid items layout
Added: trunk/LayoutTests/editing/style/apply-style-crash2-expected.txt (0 => 190634)
--- trunk/LayoutTests/editing/style/apply-style-crash2-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/style/apply-style-crash2-expected.txt 2015-10-06 19:48:24 UTC (rev 190634)
@@ -0,0 +1,2 @@
+This test passes if it does not crash.
+PASS
Added: trunk/LayoutTests/editing/style/apply-style-crash2.html (0 => 190634)
--- trunk/LayoutTests/editing/style/apply-style-crash2.html (rev 0)
+++ trunk/LayoutTests/editing/style/apply-style-crash2.html 2015-10-06 19:48:24 UTC (rev 190634)
@@ -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: trunk/LayoutTests/editing/style/apply-style-crash3-expected.txt (0 => 190634)
--- trunk/LayoutTests/editing/style/apply-style-crash3-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/style/apply-style-crash3-expected.txt 2015-10-06 19:48:24 UTC (rev 190634)
@@ -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: trunk/LayoutTests/editing/style/apply-style-crash3.html (0 => 190634)
--- trunk/LayoutTests/editing/style/apply-style-crash3.html (rev 0)
+++ trunk/LayoutTests/editing/style/apply-style-crash3.html 2015-10-06 19:48:24 UTC (rev 190634)
@@ -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: trunk/Source/WebCore/ChangeLog (190633 => 190634)
--- trunk/Source/WebCore/ChangeLog 2015-10-06 19:23:52 UTC (rev 190633)
+++ trunk/Source/WebCore/ChangeLog 2015-10-06 19:48:24 UTC (rev 190634)
@@ -1,3 +1,32 @@
+2015-10-06 Jiewen Tan <jiewen_...@apple.com>
+
+ 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 Javier Fernandez <jfernan...@igalia.com>
[CSS Grid Layout] Don't need to reset auto-margins during grid items layout
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (190633 => 190634)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2015-10-06 19:23:52 UTC (rev 190633)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2015-10-06 19:48:24 UTC (rev 190634)
@@ -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.