fix(image): decode real iPhone HEIC files instead of rejecting them at validation (#631)

validateImageBuffer() never listed heif in CLI_DECODED_FORMATS, so real iPhone HEIC uploads hit Sharp's own metadata probe (its bundled libheif only supports AV1/AVIF) and got rejected before reaching the working heif-convert/heif-dec decode path already wired up downstream. Adds heif to that set, same as raw/psd/tga/bmp/etc.

Also fixes the same gap on erase-object's mask input, which validates through the same function but had no matching decode step, so a HEIC mask reached an unguarded sharp() call and came back as a misclassified server error instead of a clean 422.

Fixes #622
This commit is contained in:
SnapOtter
2026-07-25 10:45:12 +08:00
committed by GitHub
parent 330cf559e0
commit 098ed50d06
4 changed files with 56 additions and 7 deletions
@@ -430,15 +430,17 @@ describe("validateImageBuffer - ftyp brand verification", () => {
expectRejected(await validateImageBuffer(buf), "Unrecognized image format");
});
// Uses a synthetic buffer, not a real fixture, because sharp's metadata()
// reads HEIF dimensions from the box-level `ispe` data and succeeds on real
// HEVC-coded fixtures regardless of codec support (only pixel decode needs
// it). A real fixture here would pass even without the fix below.
const heifBrands = ["heic", "heix", "mif1", "msf1", "hevc", "hevx"];
for (const brand of heifBrands) {
it(`accepts the heif brand "${brand}" (detected, then synthetic decode fails)`, async () => {
// Each brand must pass the L349 includes() check; on a synthetic buffer
// the format is heif (not CLI-decoded) and sharp fails -> metadata error.
expectRejected(
await validateImageBuffer(withFtypBrand(brand)),
"Failed to read image metadata",
);
it(`accepts the heif brand "${brand}" and returns early without a sharp decode`, async () => {
// Each brand must pass the L349 includes() check; heif is CLI-decoded
// (real HEVC decode happens later via decodeHeic()), so this must return
// valid immediately, the same as the CR3->raw arm below.
expectValid(await validateImageBuffer(withFtypBrand(brand)), "heif", 0, 0);
});
}