Skip to content

Commit fb7cda4

Browse files
author
Anu Aliyas
committed
[Backport] Fix primary display race condition crash on Windows
In rare cases, it's possible for the OS to provide us a list of displays that doesn't contain the primary display. This situation causes undefined behavior (dereference past vector end) and a crash to occur in |display::win::(anon)::DisplayInfosToScreenWinDisplays| on builds without DCHECK enabled. Bug: 40265302 Change-Id: I2154bedea84478a84147c380610c85d4ea3f703a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5353255 Reviewed-by: David Bienvenu <[email protected]> Reviewed-by: Robert Liao <[email protected]> Commit-Queue: David Bienvenu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1271793} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/650000 Reviewed-by: Moss Heim <[email protected]>
1 parent 87e3e73 commit fb7cda4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

chromium/ui/display/win/screen_win.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ std::vector<ScreenWinDisplay> DisplayInfosToScreenWinDisplays(
324324
display_infos_remaining, [](const internal::DisplayInfo& display_info) {
325325
return display_info.screen_rect().origin().IsOrigin();
326326
});
327-
DCHECK(primary_display_iter != display_infos_remaining.end());
327+
328+
// If we can't find the primary display, we likely witnessed a race condition
329+
// when querying the OS for display info. We expect another OS notification to
330+
// trigger this lookup again soon, so just return an empty list for now.
331+
if (primary_display_iter == display_infos_remaining.end()) {
332+
return {};
333+
}
328334

329335
// Build the tree and determine DisplayPlacements along the way.
330336
DisplayLayoutBuilder builder(primary_display_iter->id());

0 commit comments

Comments
 (0)