summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Vogt <fabian@ritter-vogt.de>2020-11-25 20:04:34 +0100
committerChristophe Giboudeaux <christophe@krop.fr>2020-12-04 09:12:56 +0100
commit751892a21c796130cdceaa8cee4aeeea18618c5e (patch)
treea053c2616e7adf20d1e02201ed9dd88681d5b89f
parenta34a3526828f592d16755a3b6da02ff8fbf5c32d (diff)
widgets: Avoid crash in QScroller
Quoting c6a32751 in okular[1]: QScrollerPrivate::setDpiFromWidget() before Qt 5.14 crashes when the target widget does not intersect a physical screen, because QDesktopWidget returns screen index `-1` in this case, which leads to an out-of-range read from QApplication::screens(), which leads to a segfault when reading from an invalid QScreen* pointer. [1] https://invent.kde.org/graphics/okular/-/commit/c6a32751 Fixes: QTBUG-88288 Change-Id: Ia572bf0207aa6d8ca2a209d22daa36b962e6de7d Reviewed-by: Fabian Vogt <fabian@ritter-vogt.de> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/widgets/util/qscroller.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp
index 1e84237253..8fd3437eaf 100644
--- a/src/widgets/util/qscroller.cpp
+++ b/src/widgets/util/qscroller.cpp
@@ -1031,7 +1031,8 @@ void QScrollerPrivate::setDpi(const QPointF &dpi)
*/
void QScrollerPrivate::setDpiFromWidget(QWidget *widget)
{
- const QScreen *screen = QGuiApplication::screens().at(QApplication::desktop()->screenNumber(widget));
+ const int screenNumber = QApplication::desktop()->screenNumber(widget);
+ const QScreen *screen = screenNumber < 0 ? QGuiApplication::primaryScreen() : QGuiApplication::screens().at(screenNumber);
setDpi(QPointF(screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY()));
}