qt6-qtsvg/qtsvg-verify-loading-of-invalid-svg-files-dont-crash.patch
2023-10-18 14:46:56 +02:00

116 lines
3.8 KiB
Diff

From f12f893931603bb6561149d813ca88b86e169ffd Mon Sep 17 00:00:00 2001
From: Paul Olav Tvete <paul.tvete@qt.io>
Date: Tue, 10 Oct 2023 14:25:19 +0200
Subject: [PATCH] Verify that loading of invalid SVG files don't crash
Also verify that we don't try to load invalid SVGs
twice.
Pick-to: 6.5
Task-number: QTBUG-117944
Change-Id: If3938384940112510d64a675f58c1e4e97e74986
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit 7eb8f63915a470b89b96eb274252543a22e774a7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
---
diff --git a/tests/auto/qsvgplugin/CMakeLists.txt b/tests/auto/qsvgplugin/CMakeLists.txt
index e678708..c913cd3 100644
--- a/tests/auto/qsvgplugin/CMakeLists.txt
+++ b/tests/auto/qsvgplugin/CMakeLists.txt
@@ -37,6 +37,9 @@
"simple_Utf16BE.svg"
"simple_Utf32LE.svg"
"simple_Utf32BE.svg"
+ "invalid_xml.svg"
+ "xml_not_svg.svg"
+ "invalid_then_valid.svg"
)
qt_internal_add_resource(tst_qsvgplugin "resources"
diff --git a/tests/auto/qsvgplugin/invalid_then_valid.svg b/tests/auto/qsvgplugin/invalid_then_valid.svg
new file mode 100644
index 0000000..d09f598
--- /dev/null
+++ b/tests/auto/qsvgplugin/invalid_then_valid.svg
@@ -0,0 +1,18 @@
+<!-- html-header type=current begin -->
+
+ <!DOCTYPE html>
+
+ <html lang="en">
+ <head>
+ <!-- Render IE9 -->
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ </head>
+
+<body class="anon comments ">
+
+</body></html>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" xmlns="http://www.w3.org/2000/svg">
+ <circle cx="50" cy="50" r="25" fill="#00ff00" />
+</svg>
diff --git a/tests/auto/qsvgplugin/invalid_xml.svg b/tests/auto/qsvgplugin/invalid_xml.svg
new file mode 100644
index 0000000..e0814ae
--- /dev/null
+++ b/tests/auto/qsvgplugin/invalid_xml.svg
@@ -0,0 +1,2 @@
+<!--abcd
+
diff --git a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
index 8bb401d..762d373 100644
--- a/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
+++ b/tests/auto/qsvgplugin/tst_qsvgplugin.cpp
@@ -67,6 +67,9 @@
QTest::newRow("wide_size") << QFINDTESTDATA("wide_size.svg") << 100 << 200;
QTest::newRow("wide_size_viewbox") << QFINDTESTDATA("wide_size_viewbox.svg") << 100 << 200;
QTest::newRow("wide_viewbox") << QFINDTESTDATA("wide_viewbox.svg") << 50 << 100;
+ QTest::newRow("invalid_xml") << QFINDTESTDATA("invalid_xml.svg") << 0 << 0;
+ QTest::newRow("xml_not_svg") << QFINDTESTDATA("xml_not_svg.svg") << 0 << 0;
+ QTest::newRow("invalid_then_valid") << QFINDTESTDATA("invalid_then_valid.svg") << 0 << 0;
}
void tst_QSvgPlugin::checkSize()
@@ -84,10 +87,19 @@
QImage image;
plugin.read(&image);
+ // Check that plugin survives double load
+ QVariant sizeVariant = plugin.option(QImageIOHandler::Size);
+
file.close();
QCOMPARE(imageHeight, image.height());
QCOMPARE(imageWidth, image.width());
+
+ QSize size = qvariant_cast<QSize>(sizeVariant);
+ if (size.isEmpty())
+ size = QSize(0, 0); // don't distinguish between null and invalid QSize
+ QCOMPARE(size.width(), imageWidth);
+ QCOMPARE(size.height(), imageHeight);
}
void tst_QSvgPlugin::checkImageInclude()
diff --git a/tests/auto/qsvgplugin/xml_not_svg.svg b/tests/auto/qsvgplugin/xml_not_svg.svg
new file mode 100644
index 0000000..ccefc72
--- /dev/null
+++ b/tests/auto/qsvgplugin/xml_not_svg.svg
@@ -0,0 +1,13 @@
+<!-- html-header type=current begin -->
+
+ <!DOCTYPE html>
+
+ <html lang="en">
+ <head>
+ <!-- Render IE9 -->
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ </head>
+
+<body class="anon comments ">
+
+</body></html>