Added pixel limit detected by experimental tests

This commit is contained in:
Mirco Miranda 2025-02-17 08:54:49 +01:00
parent 74a734efed
commit bb1c6aab9e
2 changed files with 13 additions and 1 deletions

View File

@ -213,7 +213,7 @@ plugin ('n/a' means no limit, i.e. the limit depends on the format encoding).
- EPS: n/a
- HDR: n/a (large image)
- HEIF: n/a
- JP2: 300,000 x 300,000 pixels
- JP2: 300,000 x 300,000 pixels, in any case no larger than 2 gigapixels
- JXL: 262,144 x 262,144 pixels, in any case no larger than 256 megapixels
- JXR: n/a, in any case no larger than 4 GB
- KRA: same size as Qt's PNG plugin

View File

@ -27,6 +27,13 @@
#define JP2_MAX_IMAGE_HEIGHT JP2_MAX_IMAGE_WIDTH
#endif
/* *** JP2_MAX_IMAGE_PIXELS ***
* OpenJPEG seems limited to an image of 2 gigapixel size.
*/
#ifndef JP2_MAX_IMAGE_PIXELS
#define JP2_MAX_IMAGE_PIXELS std::numeric_limits<qint32>::max()
#endif
/* *** JP2_ENABLE_HDR ***
* Enable float image formats. Disabled by default
* due to lack of test images.
@ -332,6 +339,11 @@ public:
return false;
}
if (qint64(width) * qint64(height) > JP2_MAX_IMAGE_PIXELS) {
qCritical() << "Maximum image size is limited to" << JP2_MAX_IMAGE_PIXELS << "pixels";
return false;
}
// OpenJPEG uses a shadow copy @32-bit/channel so we need to do a check
auto maxBytes = qint64(QImageReader::allocationLimit()) * 1024 * 1024;
auto neededBytes = qint64(width) * height * nchannels * 4;