kimgio: handle dummy BMP image size in ico plugin

fixes loading of some images such as the favicon of https://www.sftp.net/

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-30 06:22:46 +02:00
parent 90928e8320
commit bb8c1bfb2d

View file

@ -194,17 +194,6 @@ bool ICOHandler::read(QImage *image)
return false;
}
if (Q_UNLIKELY(bmpimagesize >= INT_MAX)) {
kWarning() << "BMP image size is too big" << bmpimagesize;
return false;
}
imagebytes.resize(bmpimagesize);
if (Q_UNLIKELY(datastream.readRawData(imagebytes.data(), bmpimagesize) != bmpimagesize)) {
kWarning() << "Could not read BMP image data";
return false;
}
// fallbacks
const int imagewidth = (icowidth ? icowidth : bmpwidth);
const int imageheight = (icoheight ? icoheight : bmpheight);
@ -227,6 +216,20 @@ bool ICOHandler::read(QImage *image)
}
}
if (Q_UNLIKELY(bmpimagesize == 0)) {
kDebug() << "BMP image size is dummy" << bmpimagesize << imageboundary;
bmpimagesize = imageboundary;
} else if (Q_UNLIKELY(bmpimagesize >= INT_MAX)) {
kWarning() << "BMP image size is too big" << bmpimagesize;
return false;
}
imagebytes.resize(bmpimagesize);
if (Q_UNLIKELY(datastream.readRawData(imagebytes.data(), bmpimagesize) != bmpimagesize)) {
kWarning() << "Could not read BMP image data";
return false;
}
QImage bmpimage(imagewidth, imageheight, imageformat);
if (Q_UNLIKELY(bmpimage.isNull())) {
kWarning() << "Could not create BMP image" << imagewidth << imageheight << imageformat;