summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Fella <nicolas.fella@kdab.com>2020-09-19 16:56:21 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2020-10-21 09:42:31 +0200
commit2f63ddc6afeb3d2c3c7a42add0129547acd61ede (patch)
tree042478f729ca511c66630d436391f3ebd6170538 /src
parent5f45ccdf8bc09786766e8bd2f4b8c73dd7401812 (diff)
downloadqtsvg-2f63ddc6afeb3d2c3c7a42add0129547acd61ede.tar.gz
Allow loading SVG files with a doctype declaration
SVGs may have a DOCTYPE declaration (https://www.w3.org/TR/2003/REC-SVGMobile-20030114/) in their first line. This patch makes sure those SVGs are loaded properly Fixes: QTBUG-87583 Pick-to: 5.15 5.12 Change-Id: Ia3dcb519b6ee2b498dc81ef496764d99ea6c4a9a Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> Reviewed-by: Robert Loehning <robert.loehning@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp8
-rw-r--r--src/svg/qsvgtinydocument.cpp4
2 files changed, 6 insertions, 6 deletions
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp
index 334c24b..bd39b2a 100644
--- a/src/plugins/imageformats/svg/qsvgiohandler.cpp
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -126,14 +126,14 @@ bool QSvgIOHandler::canRead() const
if (d->loaded && !d->readDone)
return true; // Will happen if we have been asked for the size
- QByteArray buf = device()->peek(8);
+ QByteArray buf = device()->peek(16);
#ifndef QT_NO_COMPRESS
if (buf.startsWith("\x1f\x8b")) {
setFormat("svgz");
return true;
} else
#endif
- if (buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--")) {
+ if (buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--") || buf.contains("<!DOCTYPE svg")) {
setFormat("svg");
return true;
}
@@ -260,12 +260,12 @@ bool QSvgIOHandler::supportsOption(ImageOption option) const
bool QSvgIOHandler::canRead(QIODevice *device)
{
- QByteArray buf = device->peek(8);
+ QByteArray buf = device->peek(16);
return
#ifndef QT_NO_COMPRESS
buf.startsWith("\x1f\x8b") ||
#endif
- buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--");
+ buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--") || buf.contains("<!DOCTYPE svg");
}
QT_END_NAMESPACE
diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp
index 5956e35..63d0797 100644
--- a/src/svg/qsvgtinydocument.cpp
+++ b/src/svg/qsvgtinydocument.cpp
@@ -159,8 +159,8 @@ static QByteArray qt_inflateSvgzDataFrom(QIODevice *device, bool doCheckContent)
if (doCheckContent) {
// Quick format check, equivalent to QSvgIOHandler::canRead()
- QByteArray buf = destination.left(8);
- if (!buf.contains("<?xml") && !buf.contains("<svg") && !buf.contains("<!--")) {
+ QByteArray buf = destination.left(16);
+ if (!buf.contains("<?xml") && !buf.contains("<svg") && !buf.contains("<!--") && !buf.contains("<!DOCTYPE svg")) {
inflateEnd(&zlibStream);
qCWarning(lcSvgHandler, "Error while inflating gzip file: SVG format check failed");
return QByteArray();