From 18322b06593bf08105f9bdeaaa4bc142ba71ec31 Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Mon, 22 Jun 2026 08:36:49 +0200 Subject: [PATCH] JP2: limits the maximum number of channels to the global value defined --- src/imageformats/jp2.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/imageformats/jp2.cpp b/src/imageformats/jp2.cpp index 01e3b39..e6d2d36 100644 --- a/src/imageformats/jp2.cpp +++ b/src/imageformats/jp2.cpp @@ -186,7 +186,7 @@ public: bool isImageValid(const opj_image_t *i) const { - return i && i->comps && i->numcomps > 0 && i->numcomps < 256; + return i && i->comps && i->numcomps > 0 && i->numcomps <= KIF_MAX_IMAGE_CHANNELS; } void enableThreads(opj_codec_t *codec) const @@ -347,11 +347,16 @@ public: bool checkSizeLimits(qint32 width, qint32 height, qint32 nchannels) const { - if (width > JP2_MAX_IMAGE_WIDTH || height > JP2_MAX_IMAGE_HEIGHT || width < 1 || height < 1) { + if (width > JP2_MAX_IMAGE_WIDTH || height > JP2_MAX_IMAGE_HEIGHT) { qCCritical(LOG_JP2PLUGIN) << "Maximum image size is limited to" << JP2_MAX_IMAGE_WIDTH << "x" << JP2_MAX_IMAGE_HEIGHT << "pixels"; return false; } + if (width < 1 || height < 1) { + qCCritical(LOG_JP2PLUGIN) << "The image size" << width << "x" << height << "pixels is not valid"; + return false; + } + if (qint64(width) * qint64(height) > JP2_MAX_IMAGE_PIXELS) { qCCritical(LOG_JP2PLUGIN) << "Maximum image size is limited to" << JP2_MAX_IMAGE_PIXELS << "pixels"; return false;