Fix crash when parsing malformed url reference
authorEirik Aavitsland <eirik.aavitsland@qt.io>
Mon, 9 Jul 2018 08:45:22 +0000 (10:45 +0200)
committerMike Gabriel <sunweaver@debian.org>
Tue, 7 May 2019 07:14:21 +0000 (08:14 +0100)
The parsing did not check for end of input.

Change-Id: I56a478877d242146395977b767511425d2b8ced1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Gbp-Pq: Name cve_2018-19869.patch

src/svg/qsvghandler.cpp
tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp

index 7004de72cf89e95520612ec6b08329b1cb5ed65a..50e039111b8b63c82db7e23051f9c06c617fe891 100644 (file)
@@ -746,16 +746,17 @@ static QVector<qreal> parsePercentageList(const QChar *&str)
 static QString idFromUrl(const QString &url)
 {
     QString::const_iterator itr = url.constBegin();
-    while ((*itr).isSpace())
+    QString::const_iterator end = url.constEnd();
+    while (itr != end && (*itr).isSpace())
         ++itr;
-    if ((*itr) == QLatin1Char('('))
+    if (itr != end && (*itr) == QLatin1Char('('))
         ++itr;
-    while ((*itr).isSpace())
+    while (itr != end && (*itr).isSpace())
         ++itr;
-    if ((*itr) == QLatin1Char('#'))
+    if (itr != end && (*itr) == QLatin1Char('#'))
         ++itr;
     QString id;
-    while ((*itr) != QLatin1Char(')')) {
+    while (itr != end && (*itr) != QLatin1Char(')')) {
         id += *itr;
         ++itr;
     }
index 6437b39df8a409faf4e97b71b81c6142368f4518..fe4591e66cc0121eccf2f75911ed0c0434e97813 100644 (file)
@@ -70,6 +70,8 @@ private slots:
     void getSetCheck();
     void inexistentUrl();
     void emptyUrl();
+    void invalidUrl_data();
+    void invalidUrl();
     void testStrokeWidth();
     void testMapViewBoxToTarget();
     void testRenderElement();
@@ -148,6 +150,30 @@ void tst_QSvgRenderer::emptyUrl()
     QVERIFY(renderer.isValid());
 }
 
+void tst_QSvgRenderer::invalidUrl_data()
+{
+    QTest::addColumn<QByteArray>("svg");
+
+    QTest::newRow("00") << QByteArray("<svg><circle fill=\"url\" /></svg>");
+    QTest::newRow("01") << QByteArray("<svg><circle fill=\"url0\" /></svg>");
+    QTest::newRow("02") << QByteArray("<svg><circle fill=\"url(0\" /></svg>");
+    QTest::newRow("03") << QByteArray("<svg><circle fill=\"url (0\" /></svg>");
+    QTest::newRow("04") << QByteArray("<svg><circle fill=\"url ( 0\" /></svg>");
+    QTest::newRow("05") << QByteArray("<svg><circle fill=\"url#\" /></svg>");
+    QTest::newRow("06") << QByteArray("<svg><circle fill=\"url#(\" /></svg>");
+    QTest::newRow("07") << QByteArray("<svg><circle fill=\"url(#\" /></svg>");
+    QTest::newRow("08") << QByteArray("<svg><circle fill=\"url(# \" /></svg>");
+    QTest::newRow("09") << QByteArray("<svg><circle fill=\"url(# 0\" /></svg>");
+}
+
+void tst_QSvgRenderer::invalidUrl()
+{
+    QFETCH(QByteArray, svg);
+
+    QSvgRenderer renderer(svg);
+    QVERIFY(renderer.isValid());
+}
+
 void tst_QSvgRenderer::testStrokeWidth()
 {
     qreal squareSize = 30.0;