Title: [288313] trunk/Source/WebCore
Revision
288313
Author
[email protected]
Date
2022-01-20 12:02:38 -0800 (Thu, 20 Jan 2022)

Log Message

AXIsolatedTree::updateChildren childrenIDs and children local variables could get out of sync
https://bugs.webkit.org/show_bug.cgi?id=235384

Reviewed by Andres Gonzalez.

In AXIsolatedTree::updateChildren, we have this:

const auto& axChildren = axAncestor->children();
auto axChildrenIDs = axAncestor->childrenIDs();

Because the current version of AXCoreObject::childrenIDs
always updates the underlying children if necessary, these
two variables could get out of sync if childrenIDs actually
performs an update after we already got children().

This patch changes childrenIDs to have the same interface as
children() by adding a `bool updateChildrenIfNecessary` parameter,
and using childrenIDs(false) in the above method.

* accessibility/AccessibilityObjectInterface.h:
(WebCore::AXCoreObject::childrenIDs):
Add updateChildrenIfNecessary parameter to match AXCoreObject::children(bool).
* accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::updateChildren):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288312 => 288313)


--- trunk/Source/WebCore/ChangeLog	2022-01-20 19:48:18 UTC (rev 288312)
+++ trunk/Source/WebCore/ChangeLog	2022-01-20 20:02:38 UTC (rev 288313)
@@ -1,3 +1,30 @@
+2022-01-20  Tyler Wilcock  <[email protected]>
+
+        AXIsolatedTree::updateChildren childrenIDs and children local variables could get out of sync
+        https://bugs.webkit.org/show_bug.cgi?id=235384
+
+        Reviewed by Andres Gonzalez.
+
+        In AXIsolatedTree::updateChildren, we have this:
+
+        const auto& axChildren = axAncestor->children();
+        auto axChildrenIDs = axAncestor->childrenIDs();
+
+        Because the current version of AXCoreObject::childrenIDs
+        always updates the underlying children if necessary, these
+        two variables could get out of sync if childrenIDs actually
+        performs an update after we already got children().
+
+        This patch changes childrenIDs to have the same interface as
+        children() by adding a `bool updateChildrenIfNecessary` parameter,
+        and using childrenIDs(false) in the above method.
+
+        * accessibility/AccessibilityObjectInterface.h:
+        (WebCore::AXCoreObject::childrenIDs):
+        Add updateChildrenIfNecessary parameter to match AXCoreObject::children(bool).
+        * accessibility/isolatedtree/AXIsolatedTree.cpp:
+        (WebCore::AXIsolatedTree::updateChildren):
+
 2022-01-20  Alexey Shvayka  <[email protected]>
 
         Callback functions / interfaces should use global object of its _value_ for errors and lifecycle

Modified: trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h (288312 => 288313)


--- trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2022-01-20 19:48:18 UTC (rev 288312)
+++ trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2022-01-20 20:02:38 UTC (rev 288313)
@@ -1272,7 +1272,7 @@
     virtual void addChildren() = 0;
     virtual void addChild(AXCoreObject*, DescendIfIgnored = DescendIfIgnored::Yes) = 0;
     virtual void insertChild(AXCoreObject*, unsigned, DescendIfIgnored = DescendIfIgnored::Yes) = 0;
-    Vector<AXID> childrenIDs();
+    Vector<AXID> childrenIDs(bool updateChildrenIfNecessary = true);
 
     virtual bool canHaveChildren() const = 0;
     virtual void updateChildrenIfNecessary() = 0;
@@ -1607,10 +1607,12 @@
 }
 #endif
 
-inline Vector<AXID> AXCoreObject::childrenIDs()
+inline Vector<AXID> AXCoreObject::childrenIDs(bool updateChildrenIfNecessary)
 {
+    auto& kids = children(updateChildrenIfNecessary);
     Vector<AXID> childrenIDs;
-    for (const auto& child : children())
+    childrenIDs.reserveCapacity(kids.size());
+    for (const auto& child : kids)
         childrenIDs.append(child->objectID());
     return childrenIDs;
 }

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp (288312 => 288313)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2022-01-20 19:48:18 UTC (rev 288312)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2022-01-20 20:02:38 UTC (rev 288313)
@@ -341,15 +341,16 @@
     auto removals = iterator->value;
 
     const auto& axChildren = axAncestor->children();
-    auto axChildrenIDs = axAncestor->childrenIDs();
+    auto axChildrenIDs = axAncestor->childrenIDs(false);
 
     bool updatedChild = false; // Set to true if at least one child's subtree is updated.
     for (size_t i = 0; i < axChildren.size() && i < axChildrenIDs.size(); ++i) {
+        ASSERT(axChildren[i]->objectID() == axChildrenIDs[i]);
+        ASSERT(axChildrenIDs[i].isValid());
         size_t index = removals.find(axChildrenIDs[i]);
         if (index != notFound)
             removals.remove(index);
         else {
-            ASSERT(axChildren[i]->objectID() == axChildrenIDs[i]);
             // This is a new child, add it to the tree.
             AXLOG("Adding a new child for:");
             AXLOG(axChildren[i]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to