From aa1bbcb5c1b871c5d862c66f4cdf1c8dd985c1ed Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 21 Mar 2024 18:33:57 +0000 Subject: [PATCH] Guard heif bitdepth property for prebuilt binaries --- lib/output.js | 4 ++++ test/unit/heif.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/output.js b/lib/output.js index c03d6506a..d7b071210 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1011,6 +1011,7 @@ function tiff (options) { * Use these AVIF options for output image. * * AVIF image sequences are not supported. + * Prebuilt binaries support a bitdepth of 8 only. * * @example * const data = await sharp(input) @@ -1097,6 +1098,9 @@ function heif (options) { } if (is.defined(options.bitdepth)) { if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [8, 10, 12])) { + if (options.bitdepth !== 8 && this.constructor.versions.heif) { + throw is.invalidParameterError('bitdepth when using prebuilt binaries', 8, options.bitdepth); + } this.options.heifBitdepth = options.bitdepth; } else { throw is.invalidParameterError('bitdepth', '8, 10 or 12', options.bitdepth); diff --git a/test/unit/heif.js b/test/unit/heif.js index ccd6a3992..be304b3dd 100644 --- a/test/unit/heif.js +++ b/test/unit/heif.js @@ -79,9 +79,16 @@ describe('HEIF', () => { }); }); it('valid bitdepth value does not throw an error', () => { + const { heif } = sharp.versions; + delete sharp.versions.heif; assert.doesNotThrow(() => { sharp().heif({ compression: 'av1', bitdepth: 12 }); }); + sharp.versions.heif = '1.2.3'; + assert.throws(() => { + sharp().heif({ compression: 'av1', bitdepth: 10 }); + }, /Error: Expected 8 for bitdepth when using prebuilt binaries but received 10 of type number/); + sharp.versions.heif = heif; }); it('invalid bitdepth value should throw an error', () => { assert.throws(() => {