Limits the max RAW size to 300000x300000 pixels

This commit is contained in:
Mirco Miranda
2025-09-21 11:52:06 +02:00
parent f28cd98661
commit a457e5ddcb
2 changed files with 31 additions and 5 deletions

View File

@ -247,7 +247,7 @@ limit depends on the format encoding).
- PXR: 65,535 x 65,535 pixels
- QOI: 300,000 x 300,000 pixels
- RAS: 300,000 x 300,000 pixels
- RAW: n/a (depends on the RAW format loaded)
- RAW: 65,535 x 65,535 pixels
- RGB: 65,535 x 65,535 pixels
- SCT: 300,000 x 300,000 pixels
- TGA: 65,535 x 65,535 pixels

View File

@ -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();
}