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

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