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

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