Title: [288290] releases/WebKitGTK/webkit-2.34
Revision
288290
Author
[email protected]
Date
2022-01-20 07:55:10 -0800 (Thu, 20 Jan 2022)

Log Message

Merge r287812 - null ptr deref in WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange
https://bugs.webkit.org/show_bug.cgi?id=234862

Patch by Gabriel Nava Marino <[email protected]> on 2022-01-08
Reviewed by Darin Adler.

Source/WebCore:

ModifySelectionListLevelCommand::appendSiblingNodeRange loops through nodes assuming
existence of siblings, which is not guaranteed, and can result in nullptr deref. Instead,
check for node existence as part of loop condition, and change raw pointer usage to RefPtr.

This addresses the crash but results in ASSERT(isEndOfParagraph(endOfParagraphToMove))
failing in CompositeEditCommand::moveParagraph. We modify WebCore::findEndOfParagraph
to check for HTMLBRElement nodes to avoid unexpectedly changing the AnchorType.

Test: http/tests/lists/list-new-parent-no-sibling-append.html

* editing/ModifySelectionListLevel.cpp:
(WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore):
(WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter):
(WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange):
* editing/VisibleUnits.cpp:
(WebCore::findEndOfParagraph):

LayoutTests:

* http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.
* http/tests/lists/list-new-parent-no-sibling-append.html: Added.
* platform/gtk/http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.
* platform/win/http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog (288289 => 288290)


--- releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog	2022-01-20 15:49:18 UTC (rev 288289)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/ChangeLog	2022-01-20 15:55:10 UTC (rev 288290)
@@ -1,3 +1,15 @@
+2022-01-08  Gabriel Nava Marino  <[email protected]>
+
+        null ptr deref in WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange
+        https://bugs.webkit.org/show_bug.cgi?id=234862
+
+        Reviewed by Darin Adler.
+
+        * http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.
+        * http/tests/lists/list-new-parent-no-sibling-append.html: Added.
+        * platform/gtk/http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.
+        * platform/win/http/tests/lists/list-new-parent-no-sibling-append-expected.txt: Added.
+
 2021-12-22  Frédéric Wang  <[email protected]>
 
         null ptr deref in DocumentTimeline::animate

Added: releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append-expected.txt (0 => 288290)


--- releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	2022-01-20 15:55:10 UTC (rev 288290)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: This test passes if it does not crash.
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. Status code: 200
+
+
+
+
+
+
+

Added: releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append.html (0 => 288290)


--- releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append.html	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/http/tests/lists/list-new-parent-no-sibling-append.html	2022-01-20 15:55:10 UTC (rev 288290)
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<style>
+  div {
+    aspect-ratio: 1;
+    mask-image: url(http://localhost:8000);
+  }
+  ol {
+    column-span: all;
+  }
+  ol:only-child {
+    column-count: 2;
+  }
+  :nth-child(2) {
+    content: url();
+  }
+</style>
+<script>
+  _onload_ = () => {
+    document.documentElement.append(document.createElement('div'));
+    document.designMode = 'on';
+    document.execCommand('SelectAll');
+    for (let i = 0; i < 10; i++) { 
+      document.execCommand('InsertNestedOrderedList');
+    }
+    if (window.testRunner)
+      testRunner.dumpAsText();
+    console.log("This test passes if it does not crash.");
+  };
+</script>

Added: releases/WebKitGTK/webkit-2.34/LayoutTests/platform/gtk/http/tests/lists/list-new-parent-no-sibling-append-expected.txt (0 => 288290)


--- releases/WebKitGTK/webkit-2.34/LayoutTests/platform/gtk/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/platform/gtk/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	2022-01-20 15:55:10 UTC (rev 288290)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: This test passes if it does not crash.
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. Status code: 404
+
+
+
+
+
+
+

Added: releases/WebKitGTK/webkit-2.34/LayoutTests/platform/win/http/tests/lists/list-new-parent-no-sibling-append-expected.txt (0 => 288290)


--- releases/WebKitGTK/webkit-2.34/LayoutTests/platform/win/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.34/LayoutTests/platform/win/http/tests/lists/list-new-parent-no-sibling-append-expected.txt	2022-01-20 15:55:10 UTC (rev 288290)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: This test passes if it does not crash.
+CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. Status code: 404
+
+
+
+
+
+
+

Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog (288289 => 288290)


--- releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog	2022-01-20 15:49:18 UTC (rev 288289)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/ChangeLog	2022-01-20 15:55:10 UTC (rev 288290)
@@ -1,3 +1,27 @@
+2022-01-08  Gabriel Nava Marino  <[email protected]>
+
+        null ptr deref in WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange
+        https://bugs.webkit.org/show_bug.cgi?id=234862
+
+        Reviewed by Darin Adler.
+
+        ModifySelectionListLevelCommand::appendSiblingNodeRange loops through nodes assuming
+        existence of siblings, which is not guaranteed, and can result in nullptr deref. Instead,
+        check for node existence as part of loop condition, and change raw pointer usage to RefPtr.
+
+        This addresses the crash but results in ASSERT(isEndOfParagraph(endOfParagraphToMove))
+        failing in CompositeEditCommand::moveParagraph. We modify WebCore::findEndOfParagraph
+        to check for HTMLBRElement nodes to avoid unexpectedly changing the AnchorType.
+
+        Test: http/tests/lists/list-new-parent-no-sibling-append.html
+
+        * editing/ModifySelectionListLevel.cpp:
+        (WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore):
+        (WebCore::ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter):
+        (WebCore::ModifySelectionListLevelCommand::appendSiblingNodeRange):
+        * editing/VisibleUnits.cpp:
+        (WebCore::findEndOfParagraph):
+
 2022-01-05  Chris Dumez  <[email protected]>
 
         [ Monterey Debug arm64 ] ASSERTION FAILED: result == &worker ./workers/service/server/SWServer.cpp(837) : void WebCore::SWServer::workerContextTerminated(WebCore::SWServerWorker &)

Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ModifySelectionListLevel.cpp (288289 => 288290)


--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ModifySelectionListLevel.cpp	2022-01-20 15:49:18 UTC (rev 288289)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/ModifySelectionListLevel.cpp	2022-01-20 15:55:10 UTC (rev 288290)
@@ -91,48 +91,52 @@
 
 void ModifySelectionListLevelCommand::insertSiblingNodeRangeBefore(Node* startNode, Node* endNode, Node* refNode)
 {
-    Node* node = startNode;
-    while (1) {
-        Node* next = node->nextSibling();
+    RefPtr node = startNode;
+    while (node) {
+        RefPtr next = node->nextSibling();
         removeNode(*node);
         insertNodeBefore(*node, *refNode);
 
         if (node == endNode)
-            break;
+            return;
 
         node = next;
     }
+    ASSERT_NOT_REACHED();
 }
 
 void ModifySelectionListLevelCommand::insertSiblingNodeRangeAfter(Node* startNode, Node* endNode, Node* refNode)
 {
-    Node* node = startNode;
-    while (1) {
-        Node* next = node->nextSibling();
+    RefPtr node = startNode;
+    RefPtr refChild = refNode;
+    while (node) {
+        RefPtr next = node->nextSibling();
         removeNode(*node);
-        insertNodeAfter(*node, *refNode);
+        insertNodeAfter(*node, *refChild);
 
         if (node == endNode)
-            break;
+            return;
 
-        refNode = node;
+        refChild = node;
         node = next;
     }
+    ASSERT_NOT_REACHED();
 }
 
 void ModifySelectionListLevelCommand::appendSiblingNodeRange(Node* startNode, Node* endNode, Element* newParent)
 {
-    Node* node = startNode;
-    while (1) {
-        Node* next = node->nextSibling();
+    RefPtr node = startNode;
+    while (node) {
+        RefPtr next = node->nextSibling();
         removeNode(*node);
         appendNode(*node, *newParent);
 
         if (node == endNode)
-            break;
+            return;
 
         node = next;
     }
+    ASSERT_NOT_REACHED();
 }
 
 IncreaseSelectionListLevelCommand::IncreaseSelectionListLevelCommand(Document& document, Type listType)

Modified: releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/VisibleUnits.cpp (288289 => 288290)


--- releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/VisibleUnits.cpp	2022-01-20 15:49:18 UTC (rev 288289)
+++ releases/WebKitGTK/webkit-2.34/Source/WebCore/editing/VisibleUnits.cpp	2022-01-20 15:55:10 UTC (rev 288290)
@@ -1181,7 +1181,7 @@
         }
         
         // FIXME: This is wrong when startNode is a block. We should return a position after the block.
-        if (r->isBR() || isBlock(n))
+        if (r->isBR() || is<HTMLBRElement>(n) || isBlock(n))
             break;
 
         // FIXME: We avoid returning a position where the renderer can't accept the caret.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to