From b85cd7d12107305012783e7f9146f0ea2e2a79cc Mon Sep 17 00:00:00 2001 From: Sayed Kaif Date: Tue, 14 Jul 2026 11:48:08 +0530 Subject: [PATCH] honour the tiff.subifd input option --- src/common.cc | 2 +- test/unit/io.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/common.cc b/src/common.cc index 354945514..15472ad5e 100644 --- a/src/common.cc +++ b/src/common.cc @@ -118,7 +118,7 @@ namespace sharp { descriptor->openSlideLevel = AttrAsUint32(input, "openSlideLevel"); } // subIFD (OME-TIFF) - if (HasAttr(input, "subifd")) { + if (HasAttr(input, "tiffSubifd")) { descriptor->tiffSubifd = AttrAsInt32(input, "tiffSubifd"); } // // PDF background color diff --git a/test/unit/io.js b/test/unit/io.js index e5e79aa86..6ff2a9843 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -1054,6 +1054,18 @@ suite('Input/output', () => { /Expected integer between -1 and 100000 for subifd but received 1.2 of type number/ ); }); + test('tiff.subifd is applied when decoding', async (t) => { + t.plan(2); + // The default main IFD (-1) decodes as usual + const { width } = await sharp(fixtures.inputTiffUncompressed, { tiff: { subifd: -1 } }).metadata(); + t.assert.strictEqual(width, 246); + // Requesting a sub-IFD reaches the loader, so a file without sub-IFDs + // now fails rather than silently decoding the main image + await t.assert.rejects( + () => sharp(fixtures.inputTiffUncompressed, { tiff: { subifd: 0 } }).toBuffer(), + /SUBIFD/ + ); + }); test('Valid pdf.background property (string)', (t) => { t.plan(1); sharp({ pdf: { background: '#00ff00' } });