Skip to content

[windows] Fix null-deref in HostWindowPopup::UpdatePosition (Fixes #191478) - #191479

Open
kryali wants to merge 1 commit into
flutter:masterfrom
kryali:fix/windows-popup-position-null-check
Open

[windows] Fix null-deref in HostWindowPopup::UpdatePosition (Fixes #191478)#191479
kryali wants to merge 1 commit into
flutter:masterfrom
kryali:fix/windows-popup-position-null-check

Conversation

@kryali

@kryali kryali commented Aug 21, 2026

Copy link
Copy Markdown

Hi there,

I recently upgraded from flutter 3.44.9 to flutter 3.47.0 and noticed that the upgrade introduced a new crash on windows. This surfaced as a EXCEPTION_ACCESS_VIOLATION_READ crash in my application.

I was able to trace the issue to HostWindowPopup and have proposed a fix with this change. This fix is modeled after the existing code in host window tooltip.

  • Guard against a null WindowRect* from the position callback, matching HostWindowTooltip::UpdatePosition's existing check for the same call. Fixes a reproducible access-violation crash when the callback returns null.

Fixes Issue #191478

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Guard against a null WindowRect* from the position callback, matching
HostWindowTooltip::UpdatePosition's existing check for the same call.
Fixes a reproducible access-violation crash when the callback returns
null. Includes a regression test.
@kryali
kryali requested a review from a team as a code owner August 21, 2026 14:39
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Aug 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a null check for the window position rectangle in HostWindowPopup::UpdatePosition to prevent crashes when the positioner fails, and adds a corresponding unit test to verify this behavior. The review feedback suggests initializing the RECT structures and asserting the success of the GetWindowRect Win32 API calls in the new unit test to avoid using uninitialized memory and prevent test flakiness.

Comment on lines +887 to +888
RECT initial_rect;
GetWindowRect(popup_window_handle, &initial_rect);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The GetWindowRect Win32 API call can fail, which would leave initial_rect uninitialized. To prevent using uninitialized memory and avoid potential test flakiness, initialize the RECT structure and assert that the API call succeeds.

Suggested change
RECT initial_rect;
GetWindowRect(popup_window_handle, &initial_rect);
RECT initial_rect = {};
ASSERT_TRUE(GetWindowRect(popup_window_handle, &initial_rect));

Comment on lines +894 to +895
RECT rect_after_null_callback;
GetWindowRect(popup_window_handle, &rect_after_null_callback);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, initialize rect_after_null_callback and assert that GetWindowRect succeeds to ensure the test does not compare uninitialized memory if the API call fails.

Suggested change
RECT rect_after_null_callback;
GetWindowRect(popup_window_handle, &rect_after_null_callback);
RECT rect_after_null_callback = {};
ASSERT_TRUE(GetWindowRect(popup_window_handle, &rect_after_null_callback));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant