- Revision
- 288252
- Author
- [email protected]
- Date
- 2022-01-19 16:22:17 -0800 (Wed, 19 Jan 2022)
Log Message
Merge r284792 - Source/WebCore:
ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
https://bugs.webkit.org/show_bug.cgi?id=232133
Patch by Gabriel Nava Marino <[email protected]> on 2021-10-25
Reviewed by Wenson Hsieh.
If the last styled node was not parent node of a current text node, but we
wish to style the text node, we will add a style span to surround the text node.
However, this requires the parent to have an editable style, or
we will not properly insert the span in the right location, which
later leads to a traversal into an invalid node. This change
makes it so we return early if the parent node does not have an
editable style, but modifying the existing
CompositeEditCommand::insertNodeBefore to return a boolean in the
early return case.
Test: fast/editing/apply-relative-font-style-change-crash-003.html
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::insertNodeBefore):
* editing/CompositeEditCommand.h:
LayoutTests:
ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
https://bugs.webkit.org/show_bug.cgi?id=232133
Patch by Gabriel Nava Marino <[email protected]> on 2021-10-25
Reviewed by Wenson Hsieh.
* fast/editing/apply-relative-font-style-change-crash-003-expected.txt: Added.
* fast/editing/apply-relative-font-style-change-crash-003.html: Added.
Modified Paths
Added Paths
Diff
Modified: releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog (288251 => 288252)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog 2022-01-20 00:22:09 UTC (rev 288251)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog 2022-01-20 00:22:17 UTC (rev 288252)
@@ -1,3 +1,13 @@
+2021-10-25 Gabriel Nava Marino <[email protected]>
+
+ ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
+ https://bugs.webkit.org/show_bug.cgi?id=232133
+
+ Reviewed by Wenson Hsieh.
+
+ * fast/editing/apply-relative-font-style-change-crash-003-expected.txt: Added.
+ * fast/editing/apply-relative-font-style-change-crash-003.html: Added.
+
2021-10-23 Rob Buis <[email protected]>
Null check in traverseNodesForSerialization
Added: releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003-expected.txt (0 => 288252)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003-expected.txt (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003-expected.txt 2022-01-20 00:22:17 UTC (rev 288252)
@@ -0,0 +1 @@
+PASS
Added: releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003.html (0 => 288252)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003.html (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/fast/editing/apply-relative-font-style-change-crash-003.html 2022-01-20 00:22:17 UTC (rev 288252)
@@ -0,0 +1,17 @@
+<head>
+ <style></style>
+ <script>
+ _onload_ = () => {
+ document.styleSheets[0].insertRule(`:last-child { content: url(); }`);
+ document.styleSheets[0].insertRule(`:last-of-type { all: initial; }`);
+ document.documentElement.prepend(document.createElement('input'));
+ document.head.appendChild(document.createElement('div'));
+ document.designMode = 'on';
+ document.execCommand('SelectAll');
+ document.execCommand('FontSizeDelta', false, '1');
+ document.write("PASS");
+ if (window.testRunner)
+ testRunner.dumpAsText();
+ };
+ </script>
+</head>
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog (288251 => 288252)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog 2022-01-20 00:22:09 UTC (rev 288251)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog 2022-01-20 00:22:17 UTC (rev 288252)
@@ -1,3 +1,28 @@
+2021-10-25 Gabriel Nava Marino <[email protected]>
+
+ ASSERT(node) triggered after surroundNodeRangeWithElement for node without editable style
+ https://bugs.webkit.org/show_bug.cgi?id=232133
+
+ Reviewed by Wenson Hsieh.
+
+ If the last styled node was not parent node of a current text node, but we
+ wish to style the text node, we will add a style span to surround the text node.
+ However, this requires the parent to have an editable style, or
+ we will not properly insert the span in the right location, which
+ later leads to a traversal into an invalid node. This change
+ makes it so we return early if the parent node does not have an
+ editable style, but modifying the existing
+ CompositeEditCommand::insertNodeBefore to return a boolean in the
+ early return case.
+
+ Test: fast/editing/apply-relative-font-style-change-crash-003.html
+
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
+ * editing/CompositeEditCommand.cpp:
+ (WebCore::CompositeEditCommand::insertNodeBefore):
+ * editing/CompositeEditCommand.h:
+
2021-10-23 Rob Buis <[email protected]>
Null check in traverseNodesForSerialization
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ApplyStyleCommand.cpp (288251 => 288252)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ApplyStyleCommand.cpp 2022-01-20 00:22:09 UTC (rev 288251)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ApplyStyleCommand.cpp 2022-01-20 00:22:17 UTC (rev 288252)
@@ -1319,8 +1319,7 @@
Ref<Node> protectedStartNode = startNode;
Ref<Element> element = WTFMove(elementToInsert);
- insertNodeBefore(element.copyRef(), startNode);
- if (!element->isContentRichlyEditable()) {
+ if (!insertNodeBefore(element.copyRef(), startNode) || !element->isContentRichlyEditable()) {
removeNode(element);
return false;
}
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.cpp (288251 => 288252)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.cpp 2022-01-20 00:22:09 UTC (rev 288251)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.cpp 2022-01-20 00:22:17 UTC (rev 288252)
@@ -551,12 +551,13 @@
return false;
}
-void CompositeEditCommand::insertNodeBefore(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
+bool CompositeEditCommand::insertNodeBefore(Ref<Node>&& insertChild, Node& refChild, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
{
auto parent = makeRefPtr(refChild.parentNode());
if (!parent || (!parent->hasEditableStyle() && parent->renderer()))
- return;
+ return false;
applyCommandToComposite(InsertNodeBeforeCommand::create(WTFMove(insertChild), refChild, shouldAssumeContentIsAlwaysEditable, editingAction()));
+ return true;
}
void CompositeEditCommand::insertNodeAfter(Ref<Node>&& insertChild, Node& refChild)
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.h (288251 => 288252)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.h 2022-01-20 00:22:09 UTC (rev 288251)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/CompositeEditCommand.h 2022-01-20 00:22:17 UTC (rev 288252)
@@ -154,7 +154,7 @@
void insertNodeAfter(Ref<Node>&&, Node& refChild);
void insertNodeAt(Ref<Node>&&, const Position&);
void insertNodeAtTabSpanPosition(Ref<Node>&&, const Position&);
- void insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
+ bool insertNodeBefore(Ref<Node>&&, Node& refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
void insertParagraphSeparatorAtPosition(const Position&, bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
void insertLineBreak();