Title: [280905] releases/WebKitGTK/webkit-2.32/Source/WebCore
Revision
280905
Author
[email protected]
Date
2021-08-11 04:24:27 -0700 (Wed, 11 Aug 2021)

Log Message

Merge r274862 - Nullptr crash in HTMLConverter::convert
https://bugs.webkit.org/show_bug.cgi?id=221719

Patch by Frédéric Wang <[email protected]> on 2021-03-23
Reviewed by Ryosuke Niwa.

When the "Undo" command is called after DOM changes, one of the selection's position anchors
may have been moved to a new document. In that case, just clear the selection. Also add
asserts to ensure the selection is in good state after unapply and reapply commands.

* editing/CompositeEditCommand.cpp:
(WebCore::EditCommandComposition::unapply): Add security assert to ensure selection is in
good state.
(WebCore::EditCommandComposition::reapply): Ditto.
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): If the selection's
position anchors have been moved to a new document then just clear the selection.
(WebCore::FrameSelection::isConnectedToDocument const): New method to verify that all the
positions of the visible selection are in m_document.
* editing/FrameSelection.h: Declare new method.
* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::document const): New method that returns a common document for
all positions or nullptr otherwise.
* editing/VisibleSelection.h: Declare new method.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-08-11 11:24:27 UTC (rev 280905)
@@ -1,3 +1,29 @@
+2021-03-23  Frédéric Wang  <[email protected]>
+
+        Nullptr crash in HTMLConverter::convert
+        https://bugs.webkit.org/show_bug.cgi?id=221719
+
+        Reviewed by Ryosuke Niwa.
+
+        When the "Undo" command is called after DOM changes, one of the selection's position anchors
+        may have been moved to a new document. In that case, just clear the selection. Also add
+        asserts to ensure the selection is in good state after unapply and reapply commands.
+
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::EditCommandComposition::unapply): Add security assert to ensure selection is in
+        good state.
+        (WebCore::EditCommandComposition::reapply): Ditto.
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance): If the selection's
+        position anchors have been moved to a new document then just clear the selection.
+        (WebCore::FrameSelection::isConnectedToDocument const): New method to verify that all the
+        positions of the visible selection are in m_document.
+        * editing/FrameSelection.h: Declare new method.
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::document const): New method that returns a common document for
+        all positions or nullptr otherwise.
+        * editing/VisibleSelection.h: Declare new method.
+
 2021-03-22  Venky Dass  <[email protected]>
 
         Nullptr crash in  WebCore::RenderObject::RenderObjectBitfields::isLineBreak() where a NULL check is missing.

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/CompositeEditCommand.cpp (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/CompositeEditCommand.cpp	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/CompositeEditCommand.cpp	2021-08-11 11:24:27 UTC (rev 280905)
@@ -243,6 +243,8 @@
 
     if (AXObjectCache::accessibilityEnabled())
         m_replacedText.postTextStateChangeNotificationForUnapply(m_document->existingAXObjectCache());
+
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_document->selection().isNone() || m_document->selection().isConnectedToDocument());
 }
 
 void EditCommandComposition::reapply()
@@ -270,6 +272,8 @@
 
     if (AXObjectCache::accessibilityEnabled())
         m_replacedText.postTextStateChangeNotificationForReapply(m_document->existingAXObjectCache());
+
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_document->selection().isNone() || m_document->selection().isConnectedToDocument());
 }
 
 void EditCommandComposition::append(SimpleEditCommand* command)

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.cpp (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.cpp	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.cpp	2021-08-11 11:24:27 UTC (rev 280905)
@@ -369,6 +369,13 @@
             return false;
         }
 
+        bool selectionEndpointsBelongToMultipleDocuments = newSelection.base().document() && !newSelection.document();
+        bool selectionIsInAnotherDocument = newSelection.document() && newSelection.document() != m_document.get();
+        if (selectionEndpointsBelongToMultipleDocuments || selectionIsInAnotherDocument) {
+            clear();
+            return false;
+        }
+
         if (closeTyping)
             TypingCommand::closeTyping(*m_document);
 
@@ -2793,6 +2800,11 @@
     return containsEndpoints(m_document, m_selection.range());
 }
 
+bool FrameSelection::isConnectedToDocument() const
+{
+    return selection().document() == m_document.get();
+}
+
 RefPtr<Range> FrameSelection::associatedLiveRange()
 {
     if (!m_associatedLiveRange) {

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.h (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.h	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/FrameSelection.h	2021-08-11 11:24:27 UTC (rev 280905)
@@ -252,6 +252,8 @@
     void setShouldShowBlockCursor(bool);
 
     bool isInDocumentTree() const;
+    bool isConnectedToDocument() const;
+
     RefPtr<Range> associatedLiveRange();
     void associateLiveRange(Range&);
     void disassociateLiveRange();

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.cpp (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.cpp	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.cpp	2021-08-11 11:24:27 UTC (rev 280905)
@@ -144,6 +144,21 @@
     return false;
 }
 
+RefPtr<Document> VisibleSelection::document() const
+{
+    auto baseDocument = makeRefPtr(m_base.document());
+    if (!baseDocument)
+        return nullptr;
+
+    if (m_extent.document() != baseDocument.get() || m_start.document() != baseDocument.get() || m_end.document() != baseDocument.get())
+        return nullptr;
+
+    if (baseDocument->settings().liveRangeSelectionEnabled() && (m_anchor.document() != baseDocument.get() || m_focus.document() != baseDocument.get()))
+        return nullptr;
+
+    return baseDocument;
+}
+
 Optional<SimpleRange> VisibleSelection::firstRange() const
 {
     if (isNoneOrOrphaned())

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.h (280904 => 280905)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.h	2021-08-11 11:20:55 UTC (rev 280904)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/editing/VisibleSelection.h	2021-08-11 11:24:27 UTC (rev 280905)
@@ -87,6 +87,7 @@
     bool isNonOrphanedRange() const { return isRange() && !start().isOrphan() && !end().isOrphan(); }
     bool isNoneOrOrphaned() const { return isNone() || start().isOrphan() || end().isOrphan(); }
     bool isOrphan() const;
+    RefPtr<Document> document() const;
 
     bool isBaseFirst() const { return m_anchorIsFirst; }
     bool isDirectional() const { return m_isDirectional; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to