From c8a0806aabeb1f3e821e0f14f4e47fc8f7e68469 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 10 Apr 2022 12:19:52 +0200 Subject: [PATCH] psd: Don't crash with broken images Found by oss-fuzz but still with an unfiled bug number --- src/imageformats/psd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/imageformats/psd.cpp b/src/imageformats/psd.cpp index 8db6892..b2dc974 100644 --- a/src/imageformats/psd.cpp +++ b/src/imageformats/psd.cpp @@ -486,6 +486,10 @@ qint64 decompress(const char *input, qint64 ilen, char *output, qint64 olen) */ static QImage::Format imageFormat(const PSDHeader &header) { + if (header.channel_count == 0) { + return QImage::Format_Invalid; + } + auto format = QImage::Format_Invalid; switch(header.color_mode) { case CM_RGB: @@ -624,7 +628,7 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img) const QImage::Format format = imageFormat(header); if (format == QImage::Format_Invalid) { - qWarning() << "Unsupported image format" << header.color_mode << header.depth; + qWarning() << "Unsupported image format. color_mode:" << header.color_mode << "depth:" << header.depth << "channel_count:" << header.channel_count; return false; }