diff --git a/docs/api-constructor.md b/docs/api-constructor.md index b9061562..5715e7a9 100644 --- a/docs/api-constructor.md +++ b/docs/api-constructor.md @@ -24,7 +24,7 @@ Implements the [stream.Duplex][1] class. * `options.limitInputPixels` **([number][14] | [boolean][15])** Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default `268402689`) - * `options.unlimited` **[boolean][15]** Set this to `true` to remove safety features that help prevent memory exhaustion (SVG, PNG, JPEG). (optional, default `false`) + * `options.unlimited` **[boolean][15]** Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). (optional, default `false`) * `options.sequentialRead` **[boolean][15]** Set this to `true` to use sequential rather than random access where possible. This can reduce memory usage and might improve performance on some systems. (optional, default `false`) * `options.density` **[number][14]** number representing the DPI for vector images in the range 1 to 100000. (optional, default `72`) diff --git a/lib/constructor.js b/lib/constructor.js index 645eecc6..431bcb3e 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -123,7 +123,7 @@ const debuglog = util.debuglog('sharp'); * @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels * (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). - * @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (SVG, PNG, JPEG). + * @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). * @param {boolean} [options.sequentialRead=false] - Set this to `true` to use sequential rather than random access where possible. * This can reduce memory usage and might improve performance on some systems. * @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000. diff --git a/src/common.cc b/src/common.cc index 9781bcde..30558dc5 100644 --- a/src/common.cc +++ b/src/common.cc @@ -164,7 +164,7 @@ namespace sharp { descriptor->limitInputPixels = static_cast(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/JPEG input + // Remove safety features and allow unlimited input descriptor->unlimited = AttrAsBool(input, "unlimited"); return descriptor; } @@ -334,6 +334,17 @@ namespace sharp { imageType == ImageType::PDF; } + /* + Does this image type support removal of safety limits? + */ + bool ImageTypeSupportsUnlimited(ImageType imageType) { + return + imageType == ImageType::JPEG || + imageType == ImageType::PNG || + imageType == ImageType::SVG || + imageType == ImageType::HEIF; + } + /* Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data) */ @@ -362,8 +373,7 @@ namespace sharp { vips::VOption *option = VImage::option() ->set("access", descriptor->access) ->set("fail_on", descriptor->failOn); - if (descriptor->unlimited && - (imageType == ImageType::SVG || imageType == ImageType::PNG || imageType == ImageType::JPEG)) { + if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) { option->set("unlimited", TRUE); } if (imageType == ImageType::SVG || imageType == ImageType::PDF) { @@ -466,8 +476,7 @@ namespace sharp { vips::VOption *option = VImage::option() ->set("access", descriptor->access) ->set("fail_on", descriptor->failOn); - if (descriptor->unlimited && - (imageType == ImageType::SVG || imageType == ImageType::PNG || imageType == ImageType::JPEG)) { + if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) { option->set("unlimited", TRUE); } if (imageType == ImageType::SVG || imageType == ImageType::PDF) { diff --git a/src/common.h b/src/common.h index ab6b5850..2e94b8c3 100644 --- a/src/common.h +++ b/src/common.h @@ -206,6 +206,11 @@ namespace sharp { */ bool ImageTypeSupportsPage(ImageType imageType); + /* + Does this image type support removal of safety limits? + */ + bool ImageTypeSupportsUnlimited(ImageType imageType); + /* Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data) */ diff --git a/test/unit/io.js b/test/unit/io.js index 2259bf15..f7b1a138 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -680,7 +680,7 @@ describe('Input/output', function () { }); }); - describe('Switch off safety limits for PNG/SVG/JPEG input', () => { + describe('Switch off safety limits for certain formats', () => { it('Valid', () => { assert.doesNotThrow(() => { sharp({ unlimited: true });