Skip to content

Commit

Permalink
Prevent renderer from crashing by invalid coordinates (#820)
Browse files Browse the repository at this point in the history
An application might send invalid coordinate which do not belong to any screen. This fixes a nullptr access by falling back to the primary screen in a such case.

PiperOrigin-RevId: 574506036
  • Loading branch information
ftake authored Oct 18, 2023
1 parent 00a0bdc commit af20906
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/renderer/qt/qt_window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,15 @@ bool QtWindowManager::ShouldShowInfolistWindow(

Rect QtWindowManager::GetMonitorRect(int x, int y) {
QPoint point{x, y};
return GetRect(QGuiApplication::screenAt(point)->geometry());
const QScreen *screen = QGuiApplication::screenAt(point);
if (screen == nullptr) {
// (x, y) does not belong to any screen. Fall back to the primary screen.
// TODO: Return the nearest monitor rect instead.
// c.f. GetWorkingAreaFromPointImpl in win32_renderer_util.cc.
return GetRect(QGuiApplication::primaryScreen()->geometry());
}

return GetRect(screen->geometry());
}

void QtWindowManager::UpdateInfolistWindow(
Expand Down

0 comments on commit af20906

Please sign in to comment.