mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 00:58:15 -04:00
psd: Protect against broken images
If you have an image that says it's Mono but has 16 as header.depth we end up doing invalid memory accesses oss-fuzz/46437
This commit is contained in:
parent
5c47a97b79
commit
9e28aae868
@ -501,10 +501,8 @@ static QImage::Format imageFormat(const PSDHeader &header)
|
||||
format = QImage::Format_Indexed8;
|
||||
break;
|
||||
case CM_BITMAP:
|
||||
format = QImage::Format_Mono;
|
||||
format = header.depth == 1 ? QImage::Format_Mono : QImage::Format_Invalid;
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Unsupported color mode" << header.color_mode;
|
||||
}
|
||||
return format;
|
||||
}
|
||||
@ -624,7 +622,13 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
return false;
|
||||
}
|
||||
|
||||
img = QImage(header.width, header.height, imageFormat(header));
|
||||
const QImage::Format format = imageFormat(header);
|
||||
if (format == QImage::Format_Invalid) {
|
||||
qWarning() << "Unsupported image format" << header.color_mode << header.depth;
|
||||
return false;
|
||||
}
|
||||
|
||||
img = QImage(header.width, header.height, format);
|
||||
if (img.isNull()) {
|
||||
qWarning() << "Failed to allocate image, invalid dimensions?" << QSize(header.width, header.height);
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user