mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-02-13 21:43:02 -05:00
Limits the max RAW size to 300000x300000 pixels
This commit is contained in:
@ -247,7 +247,7 @@ limit depends on the format encoding).
|
|||||||
- PXR: 65,535 x 65,535 pixels
|
- PXR: 65,535 x 65,535 pixels
|
||||||
- QOI: 300,000 x 300,000 pixels
|
- QOI: 300,000 x 300,000 pixels
|
||||||
- RAS: 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
|
- RGB: 65,535 x 65,535 pixels
|
||||||
- SCT: 300,000 x 300,000 pixels
|
- SCT: 300,000 x 300,000 pixels
|
||||||
- TGA: 65,535 x 65,535 pixels
|
- TGA: 65,535 x 65,535 pixels
|
||||||
|
|||||||
@ -31,6 +31,16 @@
|
|||||||
#define RAW_DISABLE_BROKEN_STREAM_PROTECTION
|
#define RAW_DISABLE_BROKEN_STREAM_PROTECTION
|
||||||
#endif
|
#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
|
#ifdef QT_DEBUG
|
||||||
/* This should be used to exclude the local QIODevice wrapper of the
|
/* This should be used to exclude the local QIODevice wrapper of the
|
||||||
* LibRaw_abstract_datastream interface. If the result changes then the problem
|
* LibRaw_abstract_datastream interface. If the result changes then the problem
|
||||||
@ -75,6 +85,18 @@ const auto supported_formats = QSet<QByteArray>{
|
|||||||
};
|
};
|
||||||
// clang-format on
|
// 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)
|
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
|
// 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
|
#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
|
// *** Unpacking selected image
|
||||||
if (rawProcessor->unpack() != LIBRAW_SUCCESS) {
|
if (rawProcessor->unpack() != LIBRAW_SUCCESS) {
|
||||||
return false;
|
return false;
|
||||||
@ -953,10 +982,7 @@ QVariant RAWHandler::option(ImageOption option) const
|
|||||||
rawProcessor->imgdata.rawparams.shot_select = currentImageNumber();
|
rawProcessor->imgdata.rawparams.shot_select = currentImageNumber();
|
||||||
#endif
|
#endif
|
||||||
if (rawProcessor->open_datastream(&stream) == LIBRAW_SUCCESS) {
|
if (rawProcessor->open_datastream(&stream) == LIBRAW_SUCCESS) {
|
||||||
auto w = libraw_get_iwidth(&rawProcessor->imgdata);
|
v = rawImageSize(rawProcessor.get());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
d->rollbackTransaction();
|
d->rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user