Bug 254798 - AXObjectCache::characterOffsetFromVisiblePosition can deref a nullptr when underlying renderer is destroyed
Summary: AXObjectCache::characterOffsetFromVisiblePosition can deref a nullptr when un...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tyler Wilcock
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-03-30 23:41 PDT by Tyler Wilcock
Modified: 2023-03-31 11:58 PDT (History)
10 users (show)

See Also:


Attachments
Patch (3.19 KB, patch)
2023-03-30 23:47 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tyler Wilcock 2023-03-30 23:41:56 PDT
AXObjectCache::characterOffsetFromVisiblePosition creates an AX object from the node backing a VisiblePosition at the beginning of the method. Then, it does non-trivial work that could cause the renderer backing the AX object to be destroyed, and afterwards unconditionally deferences that AX object's node() at the end of the method. This can cause a null pointer dereference crash (because AccessibilityRenderObject::node() depends on a non-null renderer), and is generally poor pointer hygiene.
Comment 1 Radar WebKit Bug Importer 2023-03-30 23:42:08 PDT
<rdar://problem/107459184>
Comment 2 Tyler Wilcock 2023-03-30 23:42:54 PDT
rdar://103456792
Comment 3 Tyler Wilcock 2023-03-30 23:47:09 PDT
Created attachment 465696 [details]
Patch
Comment 4 chris fleizach 2023-03-31 10:46:43 PDT
Do we still want to check that this is NOT null first?

 deepPos.deprecatedNode();
Comment 5 Tyler Wilcock 2023-03-31 10:56:30 PDT
(In reply to chris fleizach from comment #4)
> Do we still want to check that this is NOT null first?
> 
>  deepPos.deprecatedNode();
We should be safe because if `deepPos.deprecatedNode()` were null, this check just above dereferencing it would return:

if (visiblePos.isNull())
   return CharacterOffset();
Comment 6 EWS 2023-03-31 11:58:15 PDT
Committed 262432@main (7d93b07962d5): <https://commits.webkit.org/262432@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 465696 [details].