From bb8c1bfb2de339ea079afea89aa8e905c7dcbfec Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 30 Oct 2022 06:22:46 +0200 Subject: [PATCH] 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 --- kimgio/ico.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kimgio/ico.cpp b/kimgio/ico.cpp index 299c77d1..8b585854 100644 --- a/kimgio/ico.cpp +++ b/kimgio/ico.cpp @@ -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;