psd: Don't crash with broken images

Found by oss-fuzz but still with an unfiled bug number
This commit is contained in:
Albert Astals Cid
2022-04-10 12:19:52 +02:00
parent bb475dedd1
commit c8a0806aab

View File

@ -486,6 +486,10 @@ qint64 decompress(const char *input, qint64 ilen, char *output, qint64 olen)
*/ */
static QImage::Format imageFormat(const PSDHeader &header) static QImage::Format imageFormat(const PSDHeader &header)
{ {
if (header.channel_count == 0) {
return QImage::Format_Invalid;
}
auto format = QImage::Format_Invalid; auto format = QImage::Format_Invalid;
switch(header.color_mode) { switch(header.color_mode) {
case CM_RGB: case CM_RGB:
@ -624,7 +628,7 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
const QImage::Format format = imageFormat(header); const QImage::Format format = imageFormat(header);
if (format == QImage::Format_Invalid) { 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; return false;
} }