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 000000000..e86f608ed Binary files /dev/null and b/test/fixtures/65536-uint32-limit.png differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 6bb712dbb..50a77569c 100644 --- a/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()