Modified: releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog (288250 => 288251)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog 2022-01-20 00:21:58 UTC (rev 288250)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog 2022-01-20 00:22:09 UTC (rev 288251)
@@ -1,3 +1,13 @@
+2021-10-23 Rob Buis <[email protected]>
+
+ Null check in traverseNodesForSerialization
+ https://bugs.webkit.org/show_bug.cgi?id=230704
+
+ Reviewed by Wenson Hsieh.
+
+ * editing/pasteboard/copy-with-shadow-tree-crash-expected.txt: Added.
+ * editing/pasteboard/copy-with-shadow-tree-crash.html: Added.
+
2021-10-22 Gabriel Nava Marino <[email protected]>
Check if start and end positions are still valid after updating them through mergeStartWithPreviousIfIdentical
Added: releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash-expected.txt (0 => 288251)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash-expected.txt (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash-expected.txt 2022-01-20 00:22:09 UTC (rev 288251)
@@ -0,0 +1,2 @@
+This test passes if WebKit does not crash. PASS
+
Added: releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash.html (0 => 288251)
--- releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash.html (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/editing/pasteboard/copy-with-shadow-tree-crash.html 2022-01-20 00:22:09 UTC (rev 288251)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+_onload_ = () => {
+ let div0 = document.createElement('div');
+ document.body.appendChild(div0);
+ let span0 = document.createElement('span');
+ div0.appendChild(span0);
+ let div1 = document.createElement('div');
+ document.body.appendChild(div1);
+ span0.attachShadow({mode: 'open'}).appendChild(document.createElement('img'));
+ document.execCommand('SelectAll');
+ document.body.appendChild(document.createElement('input'));
+ document.designMode = 'on';
+ document.execCommand('InsertHTML', false, 'This test passes if WebKit does not crash. PASS');
+ document.designMode = 'off';
+ getSelection().modify('extend', 'left', 'lineboundary');
+ getSelection().modify('extend', 'right', 'lineboundary');
+ getSelection().extend(div1);
+ document.execCommand('Copy');
+};
+</script>
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog (288250 => 288251)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog 2022-01-20 00:21:58 UTC (rev 288250)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog 2022-01-20 00:22:09 UTC (rev 288251)
@@ -1,3 +1,19 @@
+2021-10-23 Rob Buis <[email protected]>
+
+ Null check in traverseNodesForSerialization
+ https://bugs.webkit.org/show_bug.cgi?id=230704
+
+ Reviewed by Wenson Hsieh.
+
+ Pass startNode by value instead of by pointer to
+ traverseNodesForSerialization.
+
+ Test: editing/pasteboard/copy-with-shadow-tree-crash.html
+
+ * editing/markup.cpp:
+ (WebCore::StyledMarkupAccumulator::serializeNodes):
+ (WebCore::StyledMarkupAccumulator::traverseNodesForSerialization):
+
2021-10-22 Gabriel Nava Marino <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=232177
Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/markup.cpp (288250 => 288251)
--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/markup.cpp 2022-01-20 00:21:58 UTC (rev 288250)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/markup.cpp 2022-01-20 00:22:09 UTC (rev 288251)
@@ -318,7 +318,7 @@
}
enum class NodeTraversalMode { EmitString, DoNotEmitString };
- Node* traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTraversalMode);
+ Node* traverseNodesForSerialization(Node& startNode, Node* pastEnd, NodeTraversalMode);
bool appendNodeToPreserveMSOList(Node&);
@@ -625,12 +625,14 @@
{
ASSERT(start <= end);
auto startNode = start.firstNode();
+ if (!startNode)
+ return nullptr;
Node* pastEnd = end.computeNodeAfterPosition();
if (!pastEnd && end.containerNode())
pastEnd = nextSkippingChildren(*end.containerNode());
if (!m_highestNodeToBeSerialized) {
- Node* lastClosed = traverseNodesForSerialization(startNode.get(), pastEnd, NodeTraversalMode::DoNotEmitString);
+ Node* lastClosed = traverseNodesForSerialization(*startNode, pastEnd, NodeTraversalMode::DoNotEmitString);
m_highestNodeToBeSerialized = lastClosed;
}
@@ -637,10 +639,10 @@
if (m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNode())
m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(*m_highestNodeToBeSerialized->parentNode(), shouldAnnotate(), m_standardFontFamilySerializationMode);
- return traverseNodesForSerialization(startNode.get(), pastEnd, NodeTraversalMode::EmitString);
+ return traverseNodesForSerialization(*startNode, pastEnd, NodeTraversalMode::EmitString);
}
-Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTraversalMode traversalMode)
+Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node& startNode, Node* pastEnd, NodeTraversalMode traversalMode)
{
const bool shouldEmit = traversalMode == NodeTraversalMode::EmitString;
@@ -680,7 +682,7 @@
Node* lastNode = nullptr;
Node* next = nullptr;
- for (auto* n = startNode; n != pastEnd; lastNode = n, n = next) {
+ for (auto* n = &startNode; n != pastEnd; lastNode = n, n = next) {
Vector<Node*, 8> exitedAncestors;
next = nullptr;