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

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