mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-11-22 10:02:43 -05:00
Limits the max RAW size to 300000x300000 pixels
This commit is contained in:
@ -31,6 +31,16 @@
|
||||
#define RAW_DISABLE_BROKEN_STREAM_PROTECTION
|
||||
#endif
|
||||
|
||||
/* *** RAW_MAX_IMAGE_WIDTH and RAW_MAX_IMAGE_HEIGHT ***
|
||||
* The maximum size in pixel allowed by the plugin.
|
||||
*/
|
||||
#ifndef RAW_MAX_IMAGE_WIDTH
|
||||
#define RAW_MAX_IMAGE_WIDTH std::min(65535, KIF_LARGE_IMAGE_PIXEL_LIMIT)
|
||||
#endif
|
||||
#ifndef RAW_MAX_IMAGE_HEIGHT
|
||||
#define RAW_MAX_IMAGE_HEIGHT RAW_MAX_IMAGE_WIDTH
|
||||
#endif
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
/* This should be used to exclude the local QIODevice wrapper of the
|
||||
* LibRaw_abstract_datastream interface. If the result changes then the problem
|
||||
@ -75,6 +85,18 @@ const auto supported_formats = QSet<QByteArray>{
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
/*!
|
||||
* \brief rawImageSize
|
||||
* \return The size in pixels of the RAW image.
|
||||
*/
|
||||
static QSize rawImageSize(LibRaw *rawProcessor)
|
||||
{
|
||||
auto w = libraw_get_iwidth(&rawProcessor->imgdata);
|
||||
auto h = libraw_get_iheight(&rawProcessor->imgdata);
|
||||
// flip & 4: taken from LibRaw code
|
||||
return (rawProcessor->imgdata.sizes.flip & 4) ? QSize(h, w) : QSize(w, h);
|
||||
}
|
||||
|
||||
inline int raw_scanf_one(const QByteArray &ba, const char *fmt, void *val)
|
||||
{
|
||||
// WARNING: Here it would be nice to use sscanf like LibRaw does but there
|
||||
@ -735,6 +757,13 @@ bool LoadRAW(QImageIOHandler *handler, QImage &img)
|
||||
}
|
||||
#endif
|
||||
|
||||
// *** Limiting the maximum image size on a reasonable size
|
||||
auto size = rawImageSize(rawProcessor.get());
|
||||
if (size.width() > RAW_MAX_IMAGE_WIDTH || size.height() > RAW_MAX_IMAGE_HEIGHT) {
|
||||
qCWarning(LOG_RAWPLUGIN) << "The maximum image size is limited to" << RAW_MAX_IMAGE_WIDTH << "x" << RAW_MAX_IMAGE_HEIGHT << "px";
|
||||
return false;
|
||||
}
|
||||
|
||||
// *** Unpacking selected image
|
||||
if (rawProcessor->unpack() != LIBRAW_SUCCESS) {
|
||||
return false;
|
||||
@ -953,10 +982,7 @@ QVariant RAWHandler::option(ImageOption option) const
|
||||
rawProcessor->imgdata.rawparams.shot_select = currentImageNumber();
|
||||
#endif
|
||||
if (rawProcessor->open_datastream(&stream) == LIBRAW_SUCCESS) {
|
||||
auto w = libraw_get_iwidth(&rawProcessor->imgdata);
|
||||
auto h = libraw_get_iheight(&rawProcessor->imgdata);
|
||||
// flip & 4: taken from LibRaw code
|
||||
v = (rawProcessor->imgdata.sizes.flip & 4) ? QSize(h, w) : QSize(w, h);
|
||||
v = rawImageSize(rawProcessor.get());
|
||||
}
|
||||
d->rollbackTransaction();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user