From 87d61f3283ab78a7343f4e399b099921cd9e53bd Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Mon, 5 Sep 2022 11:41:55 +0200 Subject: [PATCH] fix: limitInputPixels for highest resolution for uint32 --- src/common.cc | 3 ++- test/fixtures/65536-uint32-limit.png | Bin 0 -> 521990 bytes test/fixtures/index.js | 1 + test/unit/io.js | 11 +++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/65536-uint32-limit.png diff --git a/src/common.cc b/src/common.cc index 30558dc50..c1c02079d 100644 --- a/src/common.cc +++ b/src/common.cc @@ -507,9 +507,10 @@ namespace sharp { } } } + // Limit input images to a given number of pixels, where pixels = width * height if (descriptor->limitInputPixels > 0 && - static_cast(image.width() * image.height()) > descriptor->limitInputPixels) { + static_cast(image.width()) * static_cast(image.height()) > descriptor->limitInputPixels) { throw vips::VError("Input image exceeds pixel limit"); } return std::make_tuple(image, imageType); diff --git a/test/fixtures/65536-uint32-limit.png b/test/fixtures/65536-uint32-limit.png new file mode 100644 index 0000000000000000000000000000000000000000..e86f608ed17abc1b7c20860f0c184c78692f589f GIT binary patch literal 521990 zcmeI*yK0nM00rQGOuVB;B;WLzf~FGVj9q5_%kG3VUqH<4y*ZrqtyC$NkC(1oJh1QhzN)GYEH2Dlt$O|M z`hR*8{lBkWdb!sBYhvm0^8A^nTO03B|LT9-duQSL-KyGuWbmg~J$rt%+P(RDaqism z(PQ5~_6Glf)hB=6{n)dk|D7)a1PBlyK!5-N0t5&UAV45mVD;O>iNP-es#9BEE-bD1 zB0zuu0RjXF5FkK+009C7(gkiEIygD_UBK$^8z;`Chn0^20RjXF5FkK+009C72oP9# zG&?gj_+3D?asT!t4*~=T5FkK+009C72oNAZAYNd4bN%eU-vxZy`fzwTKCXZS2oNAZ zfB*pk1PBlyK!Ctkg8_aB2oNAZfB*pk1PBlyK!Ctl2^b6*tGb0HK!5-N0t5&UAV7cs z0RjdC{0tBvK!5-N0t5&UAV7csfiV*>7%*mq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/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -98,6 +98,7 @@ module.exports = { inputPngTrimSpecificColour: getPath('Flag_of_the_Netherlands.png'), // https://commons.wikimedia.org/wiki/File:Flag_of_the_Netherlands.svg inputPngTrimSpecificColour16bit: getPath('Flag_of_the_Netherlands-16bit.png'), // convert Flag_of_the_Netherlands.png -depth 16 Flag_of_the_Netherlands-16bit.png inputPngTrimSpecificColourIncludeAlpha: getPath('Flag_of_the_Netherlands-alpha.png'), // convert Flag_of_the_Netherlands.png -alpha set -background none -channel A -evaluate multiply 0.5 +channel Flag_of_the_Netherlands-alpha.png + inputPngUint32Limit: getPath('65536-uint32-limit.png'), // https://alexandre.alapetite.fr/doc-alex/large-image/ inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp diff --git a/test/unit/io.js b/test/unit/io.js index f7b1a1384..dd77dbb35 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -745,6 +745,17 @@ describe('Input/output', function () { }) ); + it('Enabling default limit works and fails for an image with highest resolution for uint32', () => + sharp(fixtures.inputPngUint32Limit, { limitInputPixels: true }) + .toBuffer() + .then(() => { + assert.fail('Expected to fail'); + }) + .catch(err => { + assert.strictEqual(err.message, 'Input image exceeds pixel limit'); + }) + ); + it('Smaller than input fails', () => sharp(fixtures.inputJpg) .metadata()