Blame SOURCES/0017-Correctly-detect-if-image-format-is-supported-by-QIm.patch

165ad0
From ae3ea8875b9475532e5779154e3992affe2b9a32 Mon Sep 17 00:00:00 2001
f8c1a9
From: Jan Blackquill <uhhadd@gmail.com>
f8c1a9
Date: Tue, 24 Aug 2021 14:36:34 -0400
165ad0
Subject: [PATCH 17/40] Correctly detect if image format is supported by
f8c1a9
 QImageWriter
f8c1a9
f8c1a9
The code queries potential image formats by stripping a mimetype of its
f8c1a9
'image/' prefix and making the rest of the mimetype capitalised, such as
f8c1a9
'image/png' -> 'PNG'. The problem is that this is then searched for in
f8c1a9
QImageWriter::supportedImageFormats() by simple equality. The method
f8c1a9
returns a list of lowercase byte arrays, not uppercase. As the codepath
f8c1a9
can never match due to checking for an uppercase word in an array of
f8c1a9
lowercase words, this means that images are effectively always sent as
f8c1a9
BMP format, even if they should be sent in other formats, such as PNG
f8c1a9
or JPEG.
f8c1a9
f8c1a9
A simple inspection with GDB (or a qDebug) reveals this:
f8c1a9
f8c1a9
```
f8c1a9
(gdb) p QImageWriter::supportedImageFormats()
f8c1a9
$31 = {"bmp" = {...}, "bw" = {...}, "cur" = {...}, "eps" = {...},
f8c1a9
  "epsf" = {...}, "epsi" = {...}, "icns" = {...},
f8c1a9
  "ico" = {...}, "jp2" = {...}, "jpeg" = {...}, "jpg" = {...},
f8c1a9
  "pbm" = {...}, "pcx" = {...}, "pgm" = {...},
f8c1a9
  "pic" = {...}, "png" = {...}, "ppm" = {...},
f8c1a9
  "rgb" = {...}, "rgba" = {...}, "sgi" = {...},
f8c1a9
  "tga" = {...}, "tif" = {...}, "tiff" = {...},
f8c1a9
  "wbmp" = {...}, "webp" = {...}, "xbm" = {...}, "xpm" = {...}}
f8c1a9
```
f8c1a9
f8c1a9
```
f8c1a9
(gdb) p QImageWriter::supportedImageFormats().contains("PNG")
f8c1a9
$32 = false
f8c1a9
```
f8c1a9
f8c1a9
```
f8c1a9
(gdb) p QImageWriter::supportedImageFormats().contains("png")
f8c1a9
$33 = true
f8c1a9
```
f8c1a9
f8c1a9
The fix for this is simple: lowercase the remainder of the mimetype,
f8c1a9
instead of uppercasing it, and we can start hitting the codepath that's
f8c1a9
supposed to write non-BMP formats.
f8c1a9
f8c1a9
Change-Id: Id3e9b730b7edcabcb2f1b04d8ef0a4c1fb9c9159
f8c1a9
Reviewed-by: David Edmundson <davidedmundson@kde.org>
f8c1a9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
f8c1a9
(cherry picked from commit 6072c1dc87e185f30c014f764737ac97b906640f)
f8c1a9
---
f8c1a9
 src/shared/qwaylandmimehelper.cpp | 2 +-
f8c1a9
 1 file changed, 1 insertion(+), 1 deletion(-)
f8c1a9
f8c1a9
diff --git a/src/shared/qwaylandmimehelper.cpp b/src/shared/qwaylandmimehelper.cpp
f8c1a9
index a5fdd34d..051a91dc 100644
f8c1a9
--- a/src/shared/qwaylandmimehelper.cpp
f8c1a9
+++ b/src/shared/qwaylandmimehelper.cpp
f8c1a9
@@ -60,7 +60,7 @@ QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData, const QString &
f8c1a9
             buf.open(QIODevice::ReadWrite);
f8c1a9
             QByteArray fmt = "BMP";
f8c1a9
             if (mimeType.startsWith(QLatin1String("image/"))) {
f8c1a9
-                QByteArray imgFmt = mimeType.mid(6).toUpper().toLatin1();
f8c1a9
+                QByteArray imgFmt = mimeType.mid(6).toLower().toLatin1();
f8c1a9
                 if (QImageWriter::supportedImageFormats().contains(imgFmt))
f8c1a9
                     fmt = imgFmt;
f8c1a9
             }
f8c1a9
-- 
165ad0
2.35.1
f8c1a9