summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2019-04-01 14:17:11 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2019-04-02 09:11:40 +0000
commit15f74a0f8a41759e1216d52d53852c05c9299107 (patch)
treeb25b1cb20c25a39d14e8457042f355a85dcaf009 /tests/auto
parentd477ec8f40b28caf3a216d9e8550d8871d5131fb (diff)
downloadqtsvg-15f74a0f8a41759e1216d52d53852c05c9299107.tar.gz
Fix crash for recursive gradient references
A reference loop with at least three elements would lead to endless recursion. Fixes: QTBUG-74189 Change-Id: Ie3c1b32da0e98e9218dc387dd3210666018a92e1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 5b359b9..aa28ca9 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -67,6 +67,8 @@ private slots:
void boundsOnElement() const;
void gradientStops() const;
void gradientRefs();
+ void recursiveRefs_data();
+ void recursiveRefs();
void fillRule();
void opacity();
void paths();
@@ -674,6 +676,43 @@ void tst_QSvgRenderer::gradientRefs()
}
}
+void tst_QSvgRenderer::recursiveRefs_data()
+{
+ QTest::addColumn<QByteArray>("svg");
+
+ QTest::newRow("single") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+
+ QTest::newRow("double") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#1'/>"
+ "<linearGradient id='1' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+
+ QTest::newRow("triple") << QByteArray("<svg>"
+ "<linearGradient id='0' xlink:href='#1'/>"
+ "<linearGradient id='1' xlink:href='#2'/>"
+ "<linearGradient id='2' xlink:href='#0'/>"
+ "<rect x='0' y='0' width='20' height='20' fill='url(#0)'/>"
+ "</svg>");
+}
+
+void tst_QSvgRenderer::recursiveRefs()
+{
+ QFETCH(QByteArray, svg);
+
+ QImage image(20, 20, QImage::Format_ARGB32_Premultiplied);
+ image.fill(Qt::green);
+ QImage refImage = image.copy();
+
+ QSvgRenderer renderer(svg);
+ QPainter painter(&image);
+ renderer.render(&painter);
+ QCOMPARE(image, refImage);
+}
+
#ifndef QT_NO_COMPRESS
void tst_QSvgRenderer::testGzLoading()