From 45fb1f07eaa984af40fca9f12b8f3d27f7b0e9ac Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 8 Apr 2021 13:19:52 +0200 Subject: Make image handler accept UTF-16/UTF-32 encoded SVGs The canRead() header checks assumed 8 bit encoding. Pick-to: 6.1 6.0 5.15 Fixes: QTBUG-90744 Change-Id: Ibe934fe9ed31b89ee0fbfc4562aa66ab1b359225 Reviewed-by: Allan Sandfeld Jensen --- src/plugins/imageformats/svg/qsvgiohandler.cpp | 37 +++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp index bd39b2a..4136aaf 100644 --- a/src/plugins/imageformats/svg/qsvgiohandler.cpp +++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp @@ -118,6 +118,24 @@ QSvgIOHandler::~QSvgIOHandler() delete d; } +static bool isPossiblySvg(QIODevice *device, bool *isCompressed = nullptr) +{ + constexpr int bufSize = 64; + char buf[bufSize]; + const qint64 readLen = device->peek(buf, bufSize); + if (readLen < 8) + return false; +# ifndef QT_NO_COMPRESS + if (quint8(buf[0]) == 0x1f && quint8(buf[1]) == 0x8b) { + if (isCompressed) + *isCompressed = true; + return true; + } +# endif + QTextStream str(QByteArray::fromRawData(buf, readLen)); + QByteArray ba = str.read(16).trimmed().toLatin1(); + return ba.startsWith("loaded && !d->readDone) return true; // Will happen if we have been asked for the size - QByteArray buf = device()->peek(16); -#ifndef QT_NO_COMPRESS - if (buf.startsWith("\x1f\x8b")) { - setFormat("svgz"); - return true; - } else -#endif - if (buf.contains("peek(16); - return -#ifndef QT_NO_COMPRESS - buf.startsWith("\x1f\x8b") || -#endif - buf.contains("