Skip to content

Commit

Permalink
fix: limitInputPixels for highest resolution for uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosc90 committed Sep 5, 2022
1 parent f7b29d7 commit 87d61f3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/common.cc
Expand Up @@ -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<uint64_t>(image.width() * image.height()) > descriptor->limitInputPixels) {
static_cast<uint64_t>(image.width()) * static_cast<uint64_t>(image.height()) > descriptor->limitInputPixels) {
throw vips::VError("Input image exceeds pixel limit");
}
return std::make_tuple(image, imageType);
Expand Down
Binary file added test/fixtures/65536-uint32-limit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/fixtures/index.js
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/unit/io.js
Expand Up @@ -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()
Expand Down

0 comments on commit 87d61f3

Please sign in to comment.