Fix image allocation with Qt 6

To make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit() it is necessary to allocate the image with QImageIOHandler::allocateImage().

Note that not all plugins have been changed and some others are not tested in the CI (maybe due to missing libraries).

PS: the following message is printed by QImageIOHandler::allocateImage() if the size is exceeded: "qt.gui.imageio: QImageIOHandler: Rejecting image as it exceeds the current allocation limit of XXX megabytes"
This commit is contained in:
Mirco Miranda
2022-09-07 14:03:33 +00:00
committed by Albert Astals Cid
parent dfbc6e0f8c
commit feb6d9b20f
13 changed files with 85 additions and 30 deletions

View File

@ -6,6 +6,7 @@
*/
#include "pcx_p.h"
#include "util_p.h"
#include <QColor>
#include <QDataStream>
@ -262,7 +263,7 @@ static void readImage1(QImage &img, QDataStream &s, const PCXHEADER &header)
{
QByteArray buf(header.BytesPerLine, 0);
img = QImage(header.width(), header.height(), QImage::Format_Mono);
img = imageAlloc(header.width(), header.height(), QImage::Format_Mono);
img.setColorCount(2);
if (img.isNull()) {
@ -294,7 +295,7 @@ static void readImage4(QImage &img, QDataStream &s, const PCXHEADER &header)
QByteArray buf(header.BytesPerLine * 4, 0);
QByteArray pixbuf(header.width(), 0);
img = QImage(header.width(), header.height(), QImage::Format_Indexed8);
img = imageAlloc(header.width(), header.height(), QImage::Format_Indexed8);
img.setColorCount(16);
if (img.isNull()) {
qWarning() << "Failed to allocate image, invalid dimensions?" << QSize(header.width(), header.height());
@ -338,7 +339,7 @@ static void readImage8(QImage &img, QDataStream &s, const PCXHEADER &header)
{
QByteArray buf(header.BytesPerLine, 0);
img = QImage(header.width(), header.height(), QImage::Format_Indexed8);
img = imageAlloc(header.width(), header.height(), QImage::Format_Indexed8);
img.setColorCount(256);
if (img.isNull()) {
@ -388,7 +389,7 @@ static void readImage24(QImage &img, QDataStream &s, const PCXHEADER &header)
QByteArray g_buf(header.BytesPerLine, 0);
QByteArray b_buf(header.BytesPerLine, 0);
img = QImage(header.width(), header.height(), QImage::Format_RGB32);
img = imageAlloc(header.width(), header.height(), QImage::Format_RGB32);
if (img.isNull()) {
qWarning() << "Failed to allocate image, invalid dimensions?" << QSize(header.width(), header.height());