From c136de2deb46fb5f60728bc5a4083b9439ea0a3a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 7 Feb 2025 10:29:18 +0100 Subject: [PATCH] Fix divide by zero when opening font on invalid image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you open a QFont on an invalid image, its dpi will be 0. In other places we check for this before calculating the point size, but this was missing in one spot, causing divide by zero. This would happen e.g. in the tst_QFontMetrics::same() test. While it would pass normally, running this with an undefined sanitizer build would warn about the division by zero. There's nothing useful we can do with the fonts on the invalid image, so like in the other places, we just leave the point size as is when this happens. Pick-to: 5.15 6.5 6.8 6.9 Change-Id: I4769e23e2b4dbb92f675cb8a77f8554c90bc2afd Reviewed-by: Robert Löhning --- src/gui/text/qfontdatabase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 532db11568c..72556b90dee 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -2828,7 +2828,8 @@ void QFontDatabasePrivate::load(const QFontPrivate *d, int script) req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100; req.pixelSize = qRound(req.pixelSize); } - if (req.pointSize < 0) + + if (req.pointSize < 0 && d->dpi > 0) req.pointSize = req.pixelSize*72.0/d->dpi; // respect the fallback families that might be passed through the request