Add limitInputPixels option to reject input #115

This commit is contained in:
Lovell Fuller
2015-01-20 14:18:05 +00:00
parent c93f79daa7
commit 8421e3aa5f
4 changed files with 108 additions and 4 deletions

View File

@@ -54,6 +54,7 @@ struct ResizeBaton {
void* bufferIn;
size_t bufferInLength;
std::string iccProfilePath;
int limitInputPixels;
std::string output;
std::string outputFormat;
void* bufferOut;
@@ -94,6 +95,7 @@ struct ResizeBaton {
ResizeBaton():
bufferInLength(0),
limitInputPixels(0),
outputFormat(""),
bufferOutLength(0),
topOffsetPre(-1),
@@ -178,6 +180,12 @@ class ResizeWorker : public NanAsyncWorker {
}
vips_object_local(hook, image);
// Limit input images to a given number of pixels, where pixels = width * height
if (image->Xsize * image->Ysize > baton->limitInputPixels) {
(baton->err).append("Input image exceeds pixel limit");
return Error(baton, hook);
}
// Calculate angle of rotation
Angle rotation;
bool flip;
@@ -923,6 +931,8 @@ NAN_METHOD(resize) {
}
// ICC profile to use when input CMYK image has no embedded profile
baton->iccProfilePath = *String::Utf8Value(options->Get(NanNew<String>("iccProfilePath"))->ToString());
// Limit input images to a given number of pixels, where pixels = width * height
baton->limitInputPixels = options->Get(NanNew<String>("limitInputPixels"))->Int32Value();
// Extract image options
baton->topOffsetPre = options->Get(NanNew<String>("topOffsetPre"))->Int32Value();
baton->leftOffsetPre = options->Get(NanNew<String>("leftOffsetPre"))->Int32Value();