Skip to content

Commit 4100b42

Browse files
author
Kim Motoyoshi Kalland
committed
Fixed crash when parsing invalid polygons in svgs.
Since a 2D point consists of two coordinates, it was assumed that polygons and polylines were described with an even number of coordinates. When the number of coordinates was odd, the program would read out of bounds and cause an assert failure. Task-number: QTBUG-6899 Reviewed-by: Gunnar
1 parent 4b5b748 commit 4100b42

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/svg/qsvghandler.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,14 +2722,8 @@ static QSvgNode *createPolygonNode(QSvgNode *parent,
27222722
const QChar *s = pointsStr.constData();
27232723
QVector<qreal> points = parseNumbersList(s);
27242724
QPolygonF poly(points.count()/2);
2725-
int i = 0;
2726-
QVector<qreal>::const_iterator itr = points.constBegin();
2727-
while (itr != points.constEnd()) {
2728-
qreal one = *itr; ++itr;
2729-
qreal two = *itr; ++itr;
2730-
poly[i] = QPointF(one, two);
2731-
++i;
2732-
}
2725+
for (int i = 0; i < poly.size(); ++i)
2726+
poly[i] = QPointF(points.at(2 * i), points.at(2 * i + 1));
27332727
QSvgNode *polygon = new QSvgPolygon(parent, poly);
27342728
return polygon;
27352729
}
@@ -2744,14 +2738,8 @@ static QSvgNode *createPolylineNode(QSvgNode *parent,
27442738
const QChar *s = pointsStr.constData();
27452739
QVector<qreal> points = parseNumbersList(s);
27462740
QPolygonF poly(points.count()/2);
2747-
int i = 0;
2748-
QVector<qreal>::const_iterator itr = points.constBegin();
2749-
while (itr != points.constEnd()) {
2750-
qreal one = *itr; ++itr;
2751-
qreal two = *itr; ++itr;
2752-
poly[i] = QPointF(one, two);
2753-
++i;
2754-
}
2741+
for (int i = 0; i < poly.size(); ++i)
2742+
poly[i] = QPointF(points.at(2 * i), points.at(2 * i + 1));
27552743

27562744
QSvgNode *line = new QSvgPolyline(parent, poly);
27572745
return line;

0 commit comments

Comments
 (0)