COMMIT_MESSAGE

 1AX: AccessibilityObject::insertChild does not check the validity of the insertionIndex while processing grandchildren
 2https://bugs.webkit.org/show_bug.cgi?id=241650
 3
 4Reviewed by NOBODY (OOPS!).
 5
 6When AccessibilityObject::insertChild is asked to insert a child that's
 7ignored, we instead add that object's children. However, both
 8`accessibilityIsIgnored` and `children` can cause layout, and said
 9layout could cause AccessibilityObject::m_children to be cleared. This
 10makes the `insertionIndex` invalid, which causes a crash.
 11
 12In this patch, right before m_children.insert(), we check to make sure
 13the index is still valid.
 14
 15I wasn't able to make a test for this bug. It is difficult to reproduce,
 16and the circumstances to reproduce are complex.
 17
 18* Source/WebCore/accessibility/AccessibilityObject.cpp:
 19(WebCore::AccessibilityObject::insertChild):

Source/WebCore/accessibility/AccessibilityObject.cpp

@@void AccessibilityObject::insertChild(AXCoreObject* newChild, unsigned index, De
632632 // Even though `child` is ignored, we still need to set ancestry flags based on it.
633633 grandchild->initializeAncestorFlags(childAncestorFlags);
634634 grandchild->addAncestorFlags(thisAncestorFlags);
 635 // Calls to `child->accessibilityIsIgnored()` or `child->children()` can cause layout, which in turn can cause this object to clear its m_children. This can cause `insertionIndex` to no longer be valid. Detect this and break early if necessary.
 636 if (insertionIndex > m_children.size())
 637 break;
635638 m_children.insert(insertionIndex, grandchild);
636639 ++insertionIndex;
637640 }