aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2025-04-01 13:25:37 +0800
committerMitch Curtis <mitch.curtis@qt.io>2025-04-09 09:01:31 +0800
commit8d597bea22728268beff583a79e2005b1df423bf (patch)
tree86f4000150c6d532b93e4b24ad69562d5e86fc86 /src
parent64063946db1760ec33d5329148ee14a816e6db38 (diff)
Fix division by zero in QQuickSvgParser
df97b6b2de6282bd6422f1e531a42475dadc980d in Qt Base added an assert which detected this. This patch adds an early return if we're about to divide by zero, similar to 7ca1222296a9650f24979df57cc2c974a7e571ed. It also amends that patch to move the start point == end point check to pathArc(), since it's called from more places. Fixes: QTBUG-135387 Pick-to: 5.15 6.5 6.8 6.9 Change-Id: If9c5655d5e736825e98d3e93201bf889a1785e49 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/util/qquickpath.cpp2
-rw-r--r--src/quick/util/qquicksvgparser.cpp12
2 files changed, 12 insertions, 2 deletions
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp
index 239716043a..c122d74f6d 100644
--- a/src/quick/util/qquickpath.cpp
+++ b/src/quick/util/qquickpath.cpp
@@ -2104,8 +2104,6 @@ void QQuickPathArc::addToPath(QPainterPath &path, const QQuickPathData &data)
{
const QPointF &startPoint = path.currentPosition();
const QPointF &endPoint = positionForCurve(data, startPoint);
- if (startPoint == endPoint)
- return;
QQuickSvgParser::pathArc(path,
_radiusX,
_radiusY,
diff --git a/src/quick/util/qquicksvgparser.cpp b/src/quick/util/qquicksvgparser.cpp
index 4995c3d013..59a976b65a 100644
--- a/src/quick/util/qquicksvgparser.cpp
+++ b/src/quick/util/qquicksvgparser.cpp
@@ -160,6 +160,10 @@ void QQuickSvgParser::pathArc(QPainterPath &path,
qreal y,
qreal curx, qreal cury)
{
+ // Check if the start point is equal to the end point.
+ if (QPointF(curx, cury) == QPointF(x, y))
+ return;
+
qreal sin_th, cos_th;
qreal a00, a01, a10, a11;
qreal x0, y0, x1, y1, xc, yc;
@@ -170,6 +174,14 @@ void QQuickSvgParser::pathArc(QPainterPath &path,
rx = qAbs(rx);
ry = qAbs(ry);
+ // Avoid nans and division by zero.
+ if (qFuzzyIsNull(rx) || qFuzzyIsNull(ry)) {
+ // https://www.w3.org/TR/SVG/paths.html#ArcOutOfRangeParameters says:
+ // "If either rx or ry is 0, then this arc is treated as a straight line
+ // segment (a "lineto") joining the endpoints."
+ path.lineTo(x, y);
+ return;
+ }
sin_th = qSin(qDegreesToRadians(x_axis_rotation));
cos_th = qCos(qDegreesToRadians(x_axis_rotation));