<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>241650</bug_id>
          
          <creation_ts>2022-06-15 14:47:35 -0700</creation_ts>
          <short_desc>AX: AccessibilityObject::insertChild does not check the validity of the insertionIndex while processing grandchildren</short_desc>
          <delta_ts>2022-06-16 17:21:18 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Accessibility</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tyler Wilcock">tyler_w</reporter>
          <assigned_to name="Tyler Wilcock">tyler_w</assigned_to>
          <cc>aboxhall</cc>
    
    <cc>andresg_22</cc>
    
    <cc>apinheiro</cc>
    
    <cc>cfleizach</cc>
    
    <cc>dmazzoni</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>jcraig</cc>
    
    <cc>jdiggs</cc>
    
    <cc>samuel_white</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1876087</commentid>
    <comment_count>0</comment_count>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-15 14:47:35 -0700</bug_when>
    <thetext>This can cause crashes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876088</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-06-15 14:47:42 -0700</bug_when>
    <thetext>&lt;rdar://problem/95240529&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876093</commentid>
    <comment_count>2</comment_count>
      <attachid>460262</attachid>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-15 15:03:03 -0700</bug_when>
    <thetext>Created attachment 460262
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876112</commentid>
    <comment_count>3</comment_count>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-15 16:27:10 -0700</bug_when>
    <thetext>rdar://94895437</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876137</commentid>
    <comment_count>4</comment_count>
      <attachid>460262</attachid>
    <who name="chris fleizach">cfleizach</who>
    <bug_when>2022-06-15 17:48:12 -0700</bug_when>
    <thetext>Comment on attachment 460262
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=460262&amp;action=review

&gt; Source/WebCore/accessibility/AccessibilityObject.cpp:636
&gt; +                    if (insertionIndex &gt; m_children.size())

do we want to insert this at position 0 in this case? or discard completely?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876162</commentid>
    <comment_count>5</comment_count>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-15 18:52:39 -0700</bug_when>
    <thetext>(In reply to chris fleizach from comment #4)
&gt; Comment on attachment 460262 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=460262&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/accessibility/AccessibilityObject.cpp:636
&gt; &gt; +                    if (insertionIndex &gt; m_children.size())
&gt; 
&gt; do we want to insert this at position 0 in this case? or discard completely?
I think we want to discard this grandchild (and any following) entirely, since they may no longer be the right children after the layout that caused m_children to be cleared.

Also, when this happens, m_childrenInitialized should always become false (it does in the crash I was chasing down), meaning we will add the actually-correct children in the next call to children(true).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876234</commentid>
    <comment_count>6</comment_count>
    <who name="Andres Gonzalez">andresg_22</who>
    <bug_when>2022-06-16 07:57:33 -0700</bug_when>
    <thetext>(In reply to Tyler Wilcock from comment #2)
&gt; Created attachment 460262 [details]
&gt; Patch

It seems that what we are doing in this whole block is to insert the grandchildren if the newChild is ignored. Would it make it clearer if add a method called insertchildren(const Vector&amp;, size_t index), and then we could write in the body of this block: 
    if (descendIfIgnored == DescendIfIgnored::Yes
        &amp;&amp; child-&gt;accessibilityIsIgnored()) 
        insertChildren(child-&gt;children(), index);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876277</commentid>
    <comment_count>7</comment_count>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-16 10:51:58 -0700</bug_when>
    <thetext>(In reply to Andres Gonzalez from comment #6)
&gt; (In reply to Tyler Wilcock from comment #2)
&gt; &gt; Created attachment 460262 [details]
&gt; &gt; Patch
&gt; 
&gt; It seems that what we are doing in this whole block is to insert the
&gt; grandchildren if the newChild is ignored. Would it make it clearer if add a
&gt; method called insertchildren(const Vector&amp;, size_t index), and then we could
&gt; write in the body of this block: 
&gt;     if (descendIfIgnored == DescendIfIgnored::Yes
&gt;         &amp;&amp; child-&gt;accessibilityIsIgnored()) 
&gt;         insertChildren(child-&gt;children(), index);
I tried this out and unfortunately we&apos;d also need to pass a third AXAncestorFlags parameter (to capture the flags of the ignored object), which IMO makes this refactor not worth it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876300</commentid>
    <comment_count>8</comment_count>
    <who name="Andres Gonzalez">andresg_22</who>
    <bug_when>2022-06-16 12:31:09 -0700</bug_when>
    <thetext>(In reply to Tyler Wilcock from comment #7)
&gt; (In reply to Andres Gonzalez from comment #6)
&gt; &gt; (In reply to Tyler Wilcock from comment #2)
&gt; &gt; &gt; Created attachment 460262 [details]
&gt; &gt; &gt; Patch
&gt; &gt; 
&gt; &gt; It seems that what we are doing in this whole block is to insert the
&gt; &gt; grandchildren if the newChild is ignored. Would it make it clearer if add a
&gt; &gt; method called insertchildren(const Vector&amp;, size_t index), and then we could
&gt; &gt; write in the body of this block: 
&gt; &gt;     if (descendIfIgnored == DescendIfIgnored::Yes
&gt; &gt;         &amp;&amp; child-&gt;accessibilityIsIgnored()) 
&gt; &gt;         insertChildren(child-&gt;children(), index);
&gt; I tried this out and unfortunately we&apos;d also need to pass a third
&gt; AXAncestorFlags parameter (to capture the flags of the ignored object),
&gt; which IMO makes this refactor not worth it.

No, you can do

    auto ancestorFlags = computeAncestorFlags();

inside insertObjects(...), no need to pass it as a param. Changed the name from insertchildren to insertObjects because in this case you would be inserting the grandChildren. I believe it would make the code maintainable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876304</commentid>
    <comment_count>9</comment_count>
    <who name="Andres Gonzalez">andresg_22</who>
    <bug_when>2022-06-16 12:40:36 -0700</bug_when>
    <thetext>(In reply to Andres Gonzalez from comment #8)
&gt; (In reply to Tyler Wilcock from comment #7)
&gt; &gt; (In reply to Andres Gonzalez from comment #6)
&gt; &gt; &gt; (In reply to Tyler Wilcock from comment #2)
&gt; &gt; &gt; &gt; Created attachment 460262 [details]
&gt; &gt; &gt; &gt; Patch
&gt; &gt; &gt; 
&gt; &gt; &gt; It seems that what we are doing in this whole block is to insert the
&gt; &gt; &gt; grandchildren if the newChild is ignored. Would it make it clearer if add a
&gt; &gt; &gt; method called insertchildren(const Vector&amp;, size_t index), and then we could
&gt; &gt; &gt; write in the body of this block: 
&gt; &gt; &gt;     if (descendIfIgnored == DescendIfIgnored::Yes
&gt; &gt; &gt;         &amp;&amp; child-&gt;accessibilityIsIgnored()) 
&gt; &gt; &gt;         insertChildren(child-&gt;children(), index);
&gt; &gt; I tried this out and unfortunately we&apos;d also need to pass a third
&gt; &gt; AXAncestorFlags parameter (to capture the flags of the ignored object),
&gt; &gt; which IMO makes this refactor not worth it.
&gt; 
&gt; No, you can do
&gt; 
&gt;     auto ancestorFlags = computeAncestorFlags();
&gt; 
&gt; inside insertObjects(...), no need to pass it as a param. Changed the name
&gt; from insertchildren to insertObjects because in this case you would be
&gt; inserting the grandChildren. I believe it would make the code maintainable.

The name insertChildren is fine, thought for a moment that insertObjects was better but it is not, since you are inserting children that in this case happen to be grandchildren.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876358</commentid>
    <comment_count>10</comment_count>
    <who name="Tyler Wilcock">tyler_w</who>
    <bug_when>2022-06-16 16:44:22 -0700</bug_when>
    <thetext>(In reply to Andres Gonzalez from comment #8)
&gt; (In reply to Tyler Wilcock from comment #7)
&gt; &gt; (In reply to Andres Gonzalez from comment #6)
&gt; &gt; &gt; (In reply to Tyler Wilcock from comment #2)
&gt; &gt; &gt; &gt; Created attachment 460262 [details]
&gt; &gt; &gt; &gt; Patch
&gt; &gt; &gt; 
&gt; &gt; &gt; It seems that what we are doing in this whole block is to insert the
&gt; &gt; &gt; grandchildren if the newChild is ignored. Would it make it clearer if add a
&gt; &gt; &gt; method called insertchildren(const Vector&amp;, size_t index), and then we could
&gt; &gt; &gt; write in the body of this block: 
&gt; &gt; &gt;     if (descendIfIgnored == DescendIfIgnored::Yes
&gt; &gt; &gt;         &amp;&amp; child-&gt;accessibilityIsIgnored()) 
&gt; &gt; &gt;         insertChildren(child-&gt;children(), index);
&gt; &gt; I tried this out and unfortunately we&apos;d also need to pass a third
&gt; &gt; AXAncestorFlags parameter (to capture the flags of the ignored object),
&gt; &gt; which IMO makes this refactor not worth it.
&gt; 
&gt; No, you can do
&gt; 
&gt;     auto ancestorFlags = computeAncestorFlags();
&gt; 
&gt; inside insertObjects(...), no need to pass it as a param. Changed the name
&gt; from insertchildren to insertObjects because in this case you would be
&gt; inserting the grandChildren. I believe it would make the code maintainable.
The current behavior is to use the ancestor flags of the ignored child rather than `this` as you suggest. Using `this` ancestor flags might be OK...but I don&apos;t want to make that behavior change in this patch. Let&apos;s address this refactor in a separate patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876372</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-06-16 17:21:16 -0700</bug_when>
    <thetext>Committed r295618 (251623@main): &lt;https://commits.webkit.org/251623@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 460262.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>460262</attachid>
            <date>2022-06-15 15:03:03 -0700</date>
            <delta_ts>2022-06-16 17:21:17 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-241650-20220615150303.patch</filename>
            <type>text/plain</type>
            <size>2233</size>
            <attacher name="Tyler Wilcock">tyler_w</attacher>
            
              <data encoding="base64">RnJvbSBlYWFlMDYyMDJjMmVkMTcwM2VlMjI1YzBkZTk3OTdhYjE0MWEzMjU2IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBUeWxlciBXaWxjb2NrIDx0eWxlcl93QGFwcGxlLmNvbT4KRGF0
ZTogV2VkLCAxNSBKdW4gMjAyMiAxNDo0Nzo1MCAtMDcwMApTdWJqZWN0OiBbUEFUQ0hdIEFYOiBB
Y2Nlc3NpYmlsaXR5T2JqZWN0OjppbnNlcnRDaGlsZCBkb2VzIG5vdCBjaGVjayB0aGUKIHZhbGlk
aXR5IG9mIHRoZSBpbnNlcnRpb25JbmRleCB3aGlsZSBwcm9jZXNzaW5nIGdyYW5kY2hpbGRyZW4K
IGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yNDE2NTAKClJldmlld2Vk
IGJ5IE5PQk9EWSAoT09QUyEpLgoKV2hlbiBBY2Nlc3NpYmlsaXR5T2JqZWN0OjppbnNlcnRDaGls
ZCBpcyBhc2tlZCB0byBpbnNlcnQgYSBjaGlsZCB0aGF0J3MKaWdub3JlZCwgd2UgaW5zdGVhZCBh
ZGQgdGh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IChpbnNlcnRpb25JbmRl
eCA+IG1fY2hpbGRyZW4uc2l6ZSgpKQorICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAg
ICAgICAgICAgICAgICAgICAgIG1fY2hpbGRyZW4uaW5zZXJ0KGluc2VydGlvbkluZGV4LCBncmFu
ZGNoaWxkKTsKICAgICAgICAgICAgICAgICAgICAgKytpbnNlcnRpb25JbmRleDsKICAgICAgICAg
ICAgICAgICB9Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>