Skip to content

fix: null dereference in get_SelectionContainer when no selection container exists#16091

Open
Copilot wants to merge 1 commit intomainfrom
copilot/fix-null-dereference-selection-container
Open

fix: null dereference in get_SelectionContainer when no selection container exists#16091
Copilot wants to merge 1 commit intomainfrom
copilot/fix-null-dereference-selection-container

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

get_SelectionContainer (UIA SelectionItemPattern.SelectionContainer) crashes with a null dereference when the element has no ancestor with a selection container. GetSelectionContainer() walks the parent tree looking for a view with multiselectable and required props set; if none is found it returns nullptr, which was immediately dereferenced on the next line.

What

  • Added a null check on the return value of GetSelectionContainer() in get_SelectionContainer
  • Returns S_OK with *pRetVal == nullptr when no container is found — correct per UIA spec (element is simply not inside a selection container)
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;

Screenshots

N/A

Testing

Reproduced by calling get_SelectionContainer on a selection item whose ancestor tree contains no multiselectable container. Verified the null check prevents the crash and returns S_OK with a null provider pointer.

Changelog

Should this change be included in the release notes: yes

Fix crash (null dereference) in UIA SelectionItemPattern.get_SelectionContainer when the element has no selection container ancestor.

Microsoft Reviewers: Open in CodeFlow

@vineethkuttan vineethkuttan marked this pull request as ready for review May 6, 2026 14:40
@vineethkuttan vineethkuttan requested a review from a team as a code owner May 6, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants