Allow values for limitInputPixels larger than 32-bit #3238

This commit is contained in:
Lovell Fuller
2022-05-28 08:35:17 +01:00
parent 48e3ea5e29
commit a0568ec0c3
5 changed files with 17 additions and 5 deletions

View File

@@ -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);

View File

@@ -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;