mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user