From aefa589534166786ceb888583fde5c0e493c45d5 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 18:47:55 +0000 Subject: [PATCH] fix: null dereference in get_SelectionContainer when no selection container exists (#16091) * fix: null dereference in get_SelectionContainer when no container found Agent-Logs-Url: https://github.com/microsoft/react-native-windows/sessions/dee66731-6253-459a-8ba1-f733d5bee554 Co-authored-by: vineethkuttan <66076509+vineethkuttan@users.noreply.github.com> * Change files --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vineethkuttan <66076509+vineethkuttan@users.noreply.github.com> --- ...ative-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json | 7 +++++++ .../Composition/CompositionDynamicAutomationProvider.cpp | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json diff --git a/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json b/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json new file mode 100644 index 00000000000..68ff55561cc --- /dev/null +++ b/change/react-native-windows-0ddd05a5-b75b-423a-a461-6dcafc41d3b4.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix: null dereference in get_SelectionContainer when no container found", + "packageName": "react-native-windows", + "email": "66076509+vineethkuttan@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp index 30fbc50895b..a1d7ba41d2f 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp @@ -1064,6 +1064,11 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::get_SelectionContainer(I *pRetVal = nullptr; auto selectionContainerView = GetSelectionContainer(); + // Per UIA spec, returning S_OK with *pRetVal == nullptr is correct when the element + // is not contained within a selection container. + if (!selectionContainerView) + return S_OK; + auto uiaProvider = winrt::get_self(selectionContainerView) ->EnsureUiaProvider();