From aab3348c48f8ee7e05ef92e09e4eb3a59bd21d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20L=C3=B6hning?= Date: Wed, 26 May 2021 20:57:32 +0200 Subject: [PATCH] Avoid possible division by zero "width / line.length()" didn't crash because it's a qreal but that's still undefined behavior. Fixes oss-fuzz issue 32984 Change-Id: Ia9c35b9eb5d86c4ce3c7f030b68e95ae83350c44 Reviewed-by: Eirik Aavitsland Reviewed-by: Qt CI Bot --- src/gui/painting/qpaintengine_raster.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 68ea3239f9a..5b58c32c5fb 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1649,17 +1649,18 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen) const QLineF *lines = reinterpret_cast(path.points()); for (int i = 0; i < lineCount; ++i) { - if (lines[i].p1() == lines[i].p2()) { + const QLineF line = s->matrix.map(lines[i]); + if (line.p1() == line.p2()) { if (s->lastPen.capStyle() != Qt::FlatCap) { QPointF p = lines[i].p1(); - QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*0.5, p.y()), + QLineF mappedline = s->matrix.map(QLineF(QPointF(p.x() - width*0.5, p.y()), QPointF(p.x() + width*0.5, p.y()))); - d->rasterizer->rasterizeLine(line.p1(), line.p2(), width / line.length()); + d->rasterizer->rasterizeLine(mappedline.p1(), mappedline.p2(), + width / mappedline.length()); } continue; } - const QLineF line = s->matrix.map(lines[i]); if (qpen_style(s->lastPen) == Qt::SolidLine) { d->rasterizer->rasterizeLine(line.p1(), line.p2(), width / line.length(),