Gallery fails to display images with wrong file suffix

REPRODUCIBILITY: 100%
OS VERSION: 4.5.0.24
HARDWARE: Xperia 10 III (but probably independent of the hardware)
UI LANGUAGE: German
REGRESSION: Don’t know

DESCRIPTION:

The gallery won’t open files if they have a suffix, that doesn’t match their file type (Like .png instead of .jpg). The gallery does open, but it just shows an error message that the file couldn’t be loaded though.
Files without a suffix work fine though.

PRECONDITIONS:

While this was discovered via some email attachments, in practice it can be reproduced with any image file.

STEPS TO REPRODUCE:

  1. Have an image file like: A.jpg
  2. Rename the suffix to be wrong, like: A.png
  3. Open the file (via the file browser or via gdbus call -d com.jolla.gallery -e -o /com/jolla/gallery/ui -m com.jolla.gallery.ui.openUrl '["file:/home/defaultuser/Downloads/A.png"]'

EXPECTED RESULT:

The image file opens correctly, since the file format can still be discovered and files without a suffix open correctly as well.

ACTUAL RESULT:

The file doesn’t open and shows a generic error message instead.

MODIFICATIONS:

ADDITIONAL INFORMATION:

This was discussed and troubleshooted on the fediverse: Johannes Brakensiek: "@deepbluev7@nheko.io @flypig@mastodon.social To t…" - Fosstodon

5 Likes

Thank you for reporting this issue. I have filed an error report in the internal database.

On the other hand, is this a bug of Sailfish Gallery? Somebody else has provided the Gallery with a file having an incorrect file extension. Why should the Gallery try to fix mistakes made elsewhere?

2 Likes

If QT were to rely on file endings to actually parse the contents of binaries, we’d be back in the dark ages. For an App to RELY on the naming of a file for information about the contents of the file is not a reliable way to interact with files. It also leads to having to deal with foo like '.jpg && .jpeg && .JPG ’ etc, etc.

1 Like

Reply to self: on the other hand ‘filtering a view by suffix’ is ok? I do this to limit what is viewable in a Filepicker. But I don’t really like it.
EDIT: well, having opened my fat trap, the reason I mention this is code like the following (which I put there and consider to be the ‘wrong’ ™ way)

                QFileInfo info(file);
                QDirIterator iterator(info.dir());
                while (iterator.hasNext()) {
                    iterator.next();
                    // we are explicit about two common factors, the type JPEG (ToDo: add PNG
                    // throughout all C++ source files, see issue #78), and basename cover or folder
                    if (iterator.fileInfo().isFile()) {
                        if (  (iterator.fileInfo().suffix() == "jpeg" ||
                               iterator.fileInfo().suffix() == "jpg") &&

ugly and doesn’t cover the bases.

AND the solution is: QMimeDatabase Class | Qt Core 5.15.16

QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile("/home/foobar/music", QMimeDatabase::MatchContent);
qDebug() << mime.name();            // Name of the MIME type ("audio/mpeg").
qDebug() << mime.suffixes();        // Known suffixes for this MIME type ("mp3", "mpga").
qDebug() << mime.preferredSuffix(); // Preferred suffix for this MIME type ("mp3").
2 Likes

Qt problem. Seems fixed in newer version: Loading...

2 Likes

I would agree, that people shouldn’t add incorrect extensions to files, however in this case it is related to files you receive via email. There are some rather large companies, that send out QR codes with the wrong extensions, which then fail to open in the gallery app, which is a rather frustrating experience. As such I think it is worth fixing in the Gallery app. If you remove all file extensions, the image files open correctly, so clearly the extension isn’t necessary, however some heuristics do add complications there. Ideally people would email files with the correct extensions, but I think fixing the gallery app is easier than that… :slight_smile:

2 Likes