mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add failOnError option to fail-fast on bad input image data (#976)
This commit is contained in:
committed by
Lovell Fuller
parent
382d476271
commit
b4d72bd544
@@ -52,6 +52,7 @@ namespace sharp {
|
||||
descriptor->buffer = node::Buffer::Data(buffer);
|
||||
buffersToPersist.push_back(buffer);
|
||||
}
|
||||
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
|
||||
// Density for vector-based input
|
||||
if (HasAttr(input, "density")) {
|
||||
descriptor->density = AttrTo<uint32_t>(input, "density");
|
||||
@@ -219,7 +220,9 @@ namespace sharp {
|
||||
imageType = DetermineImageType(descriptor->buffer, descriptor->bufferLength);
|
||||
if (imageType != ImageType::UNKNOWN) {
|
||||
try {
|
||||
vips::VOption *option = VImage::option()->set("access", accessMethod);
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("access", accessMethod)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", static_cast<double>(descriptor->density));
|
||||
}
|
||||
@@ -256,7 +259,9 @@ namespace sharp {
|
||||
imageType = DetermineImageType(descriptor->file.data());
|
||||
if (imageType != ImageType::UNKNOWN) {
|
||||
try {
|
||||
vips::VOption *option = VImage::option()->set("access", accessMethod);
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("access", accessMethod)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", static_cast<double>(descriptor->density));
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace sharp {
|
||||
std::string name;
|
||||
std::string file;
|
||||
char *buffer;
|
||||
bool failOnError;
|
||||
size_t bufferLength;
|
||||
int density;
|
||||
int rawChannels;
|
||||
@@ -59,6 +60,7 @@ namespace sharp {
|
||||
|
||||
InputDescriptor():
|
||||
buffer(nullptr),
|
||||
failOnError(FALSE),
|
||||
bufferLength(0),
|
||||
density(72),
|
||||
rawChannels(0),
|
||||
|
||||
@@ -249,7 +249,9 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
}
|
||||
if (shrink_on_load > 1) {
|
||||
// Reload input using shrink-on-load
|
||||
vips::VOption *option = VImage::option()->set("shrink", shrink_on_load);
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("shrink", shrink_on_load)
|
||||
->set("fail", baton->input->failOnError);
|
||||
if (baton->input->buffer != nullptr) {
|
||||
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
||||
if (inputImageType == ImageType::JPEG) {
|
||||
|
||||
Reference in New Issue
Block a user