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

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