mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Allow values for limitInputPixels larger than 32-bit #3238
This commit is contained in:
parent
48e3ea5e29
commit
a0568ec0c3
@ -6,6 +6,9 @@ Requires libvips v8.12.2
|
||||
|
||||
### v0.30.6 - TBD
|
||||
|
||||
* Allow values for `limitInputPixels` larger than 32-bit.
|
||||
[#3238](https://github.com/lovell/sharp/issues/3238)
|
||||
|
||||
* Ensure brew-installed `vips` can be detected (regression in 0.30.5).
|
||||
[#3239](https://github.com/lovell/sharp/issues/3239)
|
||||
|
||||
|
@ -86,10 +86,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels
|
||||
? Math.pow(0x3FFF, 2)
|
||||
: 0;
|
||||
} else if (is.integer(inputOptions.limitInputPixels) && inputOptions.limitInputPixels >= 0) {
|
||||
} else if (is.integer(inputOptions.limitInputPixels) && is.inRange(inputOptions.limitInputPixels, 0, Number.MAX_SAFE_INTEGER)) {
|
||||
inputDescriptor.limitInputPixels = inputOptions.limitInputPixels;
|
||||
} else {
|
||||
throw is.invalidParameterError('limitInputPixels', 'integer >= 0', inputOptions.limitInputPixels);
|
||||
throw is.invalidParameterError('limitInputPixels', 'positive integer', inputOptions.limitInputPixels);
|
||||
}
|
||||
}
|
||||
// unlimited
|
||||
|
@ -48,6 +48,9 @@ namespace sharp {
|
||||
int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr) {
|
||||
return obj.Get(attr).As<Napi::Number>().Int32Value();
|
||||
}
|
||||
int64_t AttrAsInt64(Napi::Object obj, std::string attr) {
|
||||
return obj.Get(attr).As<Napi::Number>().Int64Value();
|
||||
}
|
||||
double AttrAsDouble(Napi::Object obj, std::string attr) {
|
||||
return obj.Get(attr).As<Napi::Number>().DoubleValue();
|
||||
}
|
||||
@ -131,7 +134,7 @@ namespace sharp {
|
||||
}
|
||||
}
|
||||
// Limit input images to a given number of pixels, where pixels = width * height
|
||||
descriptor->limitInputPixels = AttrAsUint32(input, "limitInputPixels");
|
||||
descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
|
||||
// Allow switch from random to sequential access
|
||||
descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||
// Remove safety features and allow unlimited SVG/PNG input
|
||||
@ -439,7 +442,7 @@ 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()) > static_cast<uint64_t>(descriptor->limitInputPixels)) {
|
||||
static_cast<uint64_t>(image.width() * image.height()) > descriptor->limitInputPixels) {
|
||||
throw vips::VError("Input image exceeds pixel limit");
|
||||
}
|
||||
return std::make_tuple(image, imageType);
|
||||
|
@ -49,7 +49,7 @@ namespace sharp {
|
||||
std::string file;
|
||||
char *buffer;
|
||||
VipsFailOn failOn;
|
||||
int limitInputPixels;
|
||||
uint64_t limitInputPixels;
|
||||
bool unlimited;
|
||||
VipsAccess access;
|
||||
size_t bufferLength;
|
||||
|
@ -706,6 +706,12 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid fails - integer overflow', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ limitInputPixels: Number.MAX_SAFE_INTEGER + 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid fails - string', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ limitInputPixels: 'fail' });
|
||||
|
Loading…
x
Reference in New Issue
Block a user