allocationLimit = 0 means no limit

This commit is contained in:
Albert Astals Cid
2025-12-09 01:06:10 +01:00
parent 282c277204
commit 956b86c4de
2 changed files with 16 additions and 9 deletions

View File

@@ -352,12 +352,16 @@ public:
} }
// OpenJPEG uses a shadow copy @32-bit/channel so we need to do a check // OpenJPEG uses a shadow copy @32-bit/channel so we need to do a check
auto maxBytes = qint64(QImageReader::allocationLimit()) * 1024 * 1024; const int allocationLimit = QImageReader::allocationLimit();
if (allocationLimit > 0) {
auto maxBytes = qint64(allocationLimit) * 1024 * 1024;
auto neededBytes = qint64(width) * height * nchannels * 4; auto neededBytes = qint64(width) * height * nchannels * 4;
if (maxBytes > 0 && neededBytes > maxBytes) { if (maxBytes > 0 && neededBytes > maxBytes) {
qCCritical(LOG_JP2PLUGIN) << "Allocation limit set to" << (maxBytes / 1024 / 1024) << "MiB but" << (neededBytes / 1024 / 1024) << "MiB are needed!"; qCCritical(LOG_JP2PLUGIN) << "Allocation limit set to" << (maxBytes / 1024 / 1024) << "MiB but" << (neededBytes / 1024 / 1024)
<< "MiB are needed!";
return false; return false;
} }
}
return true; return true;
} }

View File

@@ -1389,11 +1389,14 @@ bool XCFImageFormat::composeTiles(XCFImage &xcf_image)
// tiles of 64x64 pixels. The required memory to build the image is at least doubled because tiles are loaded // tiles of 64x64 pixels. The required memory to build the image is at least doubled because tiles are loaded
// and then the final image is created by copying the tiles inside it. // and then the final image is created by copying the tiles inside it.
// NOTE: on Windows to open a 10GiB image the plugin uses 28GiB of RAM // NOTE: on Windows to open a 10GiB image the plugin uses 28GiB of RAM
qint64 channels = 1 + (layer.type == RGB_GIMAGE ? 2 : 0) + (layer.type == RGBA_GIMAGE ? 3 : 0); const qint64 channels = 1 + (layer.type == RGB_GIMAGE ? 2 : 0) + (layer.type == RGBA_GIMAGE ? 3 : 0);
if (qint64(layer.width) * qint64(layer.height) * channels * 2ll / 1024ll / 1024ll > QImageReader::allocationLimit()) { const int allocationLimit = QImageReader::allocationLimit();
qCDebug(XCFPLUGIN) << "Rejecting image as it exceeds the current allocation limit of" << QImageReader::allocationLimit() << "megabytes"; if (allocationLimit > 0) {
if (qint64(layer.width) * qint64(layer.height) * channels * 2ll / 1024ll / 1024ll > allocationLimit) {
qCDebug(XCFPLUGIN) << "Rejecting image as it exceeds the current allocation limit of" << allocationLimit << "megabytes";
return false; return false;
} }
}
#endif #endif
layer.image_tiles.resize(layer.nrows); layer.image_tiles.resize(layer.nrows);