From 5b5d2868e2f0ba9aca6c5f2fbe8a30838db48c9c Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Thu, 23 Jan 2025 01:16:04 +1300 Subject: [PATCH] Desktop: Fix Crash when Adding JPG Image on MacOS. Fix a crash on MacOS when trying to open a JPG image with libraw by filtering files by valid extensions for RAW files. Fixes #4377. Signed-off-by: Michael Keller --- core/imagedownloader.cpp | 8 ++++---- core/qthelper.cpp | 2 +- core/qthelper.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index 9b5d3e558..589beeb40 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -74,9 +74,9 @@ void ImageDownloader::saveImage(QNetworkReply *reply) reply->deleteLater(); } -static bool hasVideoFileExtension(const QString &filename) +static bool hasFileExtension(const QString &filename, const QStringList extensionsList) { - for (const QString &ext: videoExtensionsList) + for (const QString &ext: extensionsList) if (filename.endsWith(ext, Qt::CaseInsensitive)) return true; return false; @@ -136,7 +136,7 @@ Thumbnailer::Thumbnail Thumbnailer::fetchImage(const QString &urlfilename, const #ifdef LIBRAW_SUPPORT // If note, perhaps a raw image? - if (thumb.isNull()) + if (thumb.isNull() && hasFileExtension(filename, rawExtensionsList)) thumb = fetchRawThumbnail(filename); #endif if (!thumb.isNull()) { @@ -148,7 +148,7 @@ Thumbnailer::Thumbnail Thumbnailer::fetchImage(const QString &urlfilename, const // Neither our code, nor Qt could determine the type of this object from looking at the data. // Try to check for a video-file extension. Since we couldn't parse the video file, // we pass 0 as the duration. - if (hasVideoFileExtension(filename)) + if (hasFileExtension(filename, videoExtensionsList)) return fetchVideoThumbnail(filename, originalFilename, duration_t()); // Give up: we simply couldn't determine what this thing is. diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 9ddbd8590..6fb5afe24 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -1092,7 +1092,7 @@ const QStringList videoExtensionsList = { }; // Raw extensions according to https://en.wikipedia.org/wiki/Raw_image_format -static const QStringList rawExtensionsList = { +const QStringList rawExtensionsList = { #ifdef LIBRAW_SUPPORT "*.3fr", "*.ari", "*.arw", "*.bay", "*.braw", "*.crw", "*.cr2", "*.cr3", "*.cap", "*.data", "*.dcs", "*.dcr", "*.dng", "*.drf", "*.eip", "*.erf", "*.fff", "*.gpr", diff --git a/core/qthelper.h b/core/qthelper.h index 75ee8b15c..30f71789d 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -41,6 +41,7 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude); void init_proxy(); QStringList getWaterTypesAsString(); extern const QStringList videoExtensionsList; +extern const QStringList rawExtensionsList; QStringList mediaExtensionFilters(); QStringList imageExtensionFilters(); QStringList videoExtensionFilters();