summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2023-10-06 14:48:29 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2023-10-10 00:57:11 +0200
commit888be431da9bbdaca7dd32ba0975e206790c5c42 (patch)
treef9ffaef39642e67713311336d2f6333db7e62932 /src/gui/painting
parentebf1538fa6fce9a85331474098c517d618b06740 (diff)
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.6 6.5 Change-Id: I247b0612bd565fb2e6f47a182e74f19b8bb0d683 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qpdf.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 02fd2fdeea..d49249b1dd 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<quint32>::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) {