RESOLVED FIXED 235384
AXIsolatedTree::updateChildren childrenIDs and children local variables could get out of sync
https://bugs.webkit.org/show_bug.cgi?id=235384
Summary AXIsolatedTree::updateChildren childrenIDs and children local variables could...
Tyler Wilcock
Reported 2022-01-19 14:35:29 PST
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().
Attachments
Patch (4.13 KB, patch)
2022-01-19 14:42 PST, Tyler Wilcock
no flags
Radar WebKit Bug Importer
Comment 1 2022-01-19 14:35:46 PST
Tyler Wilcock
Comment 2 2022-01-19 14:42:45 PST
Andres Gonzalez
Comment 3 2022-01-20 10:57:12 PST
(In reply to Tyler Wilcock from comment #2) > Created attachment 449519 [details] > Patch No need to add a bool param to ChildrenIDs since it is never used with value true. Keeping it simple, we can say that childrenIDs returns the IDs of the current children.
Tyler Wilcock
Comment 4 2022-01-20 11:09:00 PST
(In reply to Andres Gonzalez from comment #3) > (In reply to Tyler Wilcock from comment #2) > > Created attachment 449519 [details] > > Patch > > No need to add a bool param to ChildrenIDs since it is never used with value > true. Keeping it simple, we can say that childrenIDs returns the IDs of the > current children. Well, it's used in places outside this patch in ways that do expect childrenIDs to update if necessary. For example, this: void AXIsolatedTree::updateNode(AXCoreObject& axObject) { ...truncated... auto newObject = AXIsolatedObject::create(axObject, this, parentID); newObject->m_childrenIDs = axObject.childrenIDs(); ...truncated... } I did try to make childrenIDs be non-updating always, but that causes ~10 additional ITM failures. So I opted to give childrenIDs() the same bool API that children() has and fix the definitely wrong usage of it in AXIsolatedTree::updateChildren.
Andres Gonzalez
Comment 5 2022-01-20 11:14:50 PST
(In reply to Tyler Wilcock from comment #4) > (In reply to Andres Gonzalez from comment #3) > > (In reply to Tyler Wilcock from comment #2) > > > Created attachment 449519 [details] > > > Patch > > > > No need to add a bool param to ChildrenIDs since it is never used with value > > true. Keeping it simple, we can say that childrenIDs returns the IDs of the > > current children. > Well, it's used in places outside this patch in ways that do expect > childrenIDs to update if necessary. For example, this: > > void AXIsolatedTree::updateNode(AXCoreObject& axObject) > { > ...truncated... > auto newObject = AXIsolatedObject::create(axObject, this, parentID); > newObject->m_childrenIDs = axObject.childrenIDs(); > ...truncated... > } > > I did try to make childrenIDs be non-updating always, but that causes ~10 > additional ITM failures. So I opted to give childrenIDs() the same bool API > that children() has and fix the definitely wrong usage of it in > AXIsolatedTree::updateChildren. OK, thanks.
Tyler Wilcock
Comment 6 2022-01-20 11:18:17 PST
Thank you both for the review!
EWS
Comment 7 2022-01-20 12:03:48 PST
Committed r288313 (246229@main): <https://commits.webkit.org/246229@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 449519 [details].
Darin Adler
Comment 8 2022-01-20 13:04:00 PST
Comment on attachment 449519 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=449519&action=review > Source/WebCore/accessibility/AccessibilityObjectInterface.h:1612 > + auto& kids = children(updateChildrenIfNecessary); It’s more elegant to use Vector::map instead of a loop and easier to get the vector size allocation right; something to consider in future. > Source/WebCore/accessibility/AccessibilityObjectInterface.h:1614 > + childrenIDs.reserveCapacity(kids.size()); This should use reserveInitialCapacity, slightly more efficient. > Source/WebCore/accessibility/AccessibilityObjectInterface.h:1615 > + for (const auto& child : kids) This can just use auto&, no need for the const. > Source/WebCore/accessibility/AccessibilityObjectInterface.h:1616 > childrenIDs.append(child->objectID()); This can use the slightly more efficient uncheckedAppend because of the reserveCapacity above.
Note You need to log in before you can comment on or make changes to this bug.