From af209061632ba7dcc64b63bd06eb988974375508 Mon Sep 17 00:00:00 2001 From: Fuminobu TAKEYAMA Date: Thu, 19 Oct 2023 02:01:45 +0900 Subject: [PATCH] Prevent renderer from crashing by invalid coordinates (#820) 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 --- src/renderer/qt/qt_window_manager.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/renderer/qt/qt_window_manager.cc b/src/renderer/qt/qt_window_manager.cc index 55f6acbf6..0aceecce6 100644 --- a/src/renderer/qt/qt_window_manager.cc +++ b/src/renderer/qt/qt_window_manager.cc @@ -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(