From 696fbf9fc439f361811fbc027a7e0bbebdb68a85 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 6 Oct 2023 14:48:29 +0200 Subject: [PATCH] Avoid generating corrupt pdf output for out of range coordinates The local qreal to string conversion would fail and produce unsyntactic output if the integer part exceeded the range of an unsigned int. Introduce check for that, and fall back to just output a 0 value instead in such cases. Testing indicates that there is no point in supporting values beyond 4G, as pdf readers do not seem to accept higher values anyway. As a driveby, also extend the check to catch all non-finite real values, not only nan. As a second driveby, simplify the splitting of a qreal into integer and fraction parts by just using the std library function for that. Fixes: QTBUG-117740 Pick-to: 6.5 Change-Id: I247b0612bd565fb2e6f47a182e74f19b8bb0d683 Reviewed-by: Shawn Rutledge (cherry picked from commit 888be431da9bbdaca7dd32ba0975e206790c5c42) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qpdf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 02fd2fdeea1..d49249b1dda 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -99,7 +99,7 @@ static void removeTransparencyFromBrush(QBrush &brush) const char *qt_real_to_string(qreal val, char *buf) { const char *ret = buf; - if (qIsNaN(val)) { + if (!qIsFinite(val) || std::abs(val) > std::numeric_limits::max()) { *(buf++) = '0'; *(buf++) = ' '; *buf = 0; @@ -110,8 +110,8 @@ const char *qt_real_to_string(qreal val, char *buf) { *(buf++) = '-'; val = -val; } - unsigned int ival = (unsigned int) val; - qreal frac = val - (qreal)ival; + qreal frac = std::modf(val, &val); + quint32 ival(val); int ifrac = (int)(frac * 1000000000); if (ifrac == 1000000000) {