From 5c8f740c2a040d86a592c68c22b423ef05350de7 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Mon, 6 Dec 2021 12:20:27 -0500 Subject: [PATCH] Check filename extension for heic/heif images --- ts/types/MIME.ts | 7 +++++-- ts/util/handleImageAttachment.ts | 6 ++++-- ts/util/processAttachment.ts | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ts/types/MIME.ts b/ts/types/MIME.ts index 85be83fa3..6ad989498 100644 --- a/ts/types/MIME.ts +++ b/ts/types/MIME.ts @@ -26,8 +26,11 @@ export const VIDEO_MP4 = stringToMIMEType('video/mp4'); export const VIDEO_QUICKTIME = stringToMIMEType('video/quicktime'); export const LONG_MESSAGE = stringToMIMEType('text/x-signal-plain'); -export const isHeic = (value: string): boolean => - value === 'image/heic' || value === 'image/heif'; +export const isHeic = (value: string, fileName: string): boolean => + value === 'image/heic' || + value === 'image/heif' || + fileName.endsWith('.heic') || + fileName.endsWith('.heif'); export const isGif = (value: string): value is MIMEType => value === 'image/gif'; export const isJPEG = (value: string): value is MIMEType => diff --git a/ts/util/handleImageAttachment.ts b/ts/util/handleImageAttachment.ts index 99954e920..5b15a207a 100644 --- a/ts/util/handleImageAttachment.ts +++ b/ts/util/handleImageAttachment.ts @@ -18,7 +18,7 @@ export async function handleImageAttachment( ): Promise { let processedFile: File | Blob = file; - if (isHeic(file.type)) { + if (isHeic(file.type, file.name)) { const uuid = genUuid(); const bytes = new Uint8Array(await file.arrayBuffer()); @@ -41,7 +41,9 @@ export async function handleImageAttachment( file: resizedBlob, fileName, } = await autoScale({ - contentType: isHeic(file.type) ? IMAGE_JPEG : stringToMIMEType(file.type), + contentType: isHeic(file.type, file.name) + ? IMAGE_JPEG + : stringToMIMEType(file.type), fileName: file.name, file: processedFile, }); diff --git a/ts/util/processAttachment.ts b/ts/util/processAttachment.ts index d818dfb88..b85a63b16 100644 --- a/ts/util/processAttachment.ts +++ b/ts/util/processAttachment.ts @@ -82,7 +82,7 @@ export async function processAttachment( let attachment: InMemoryAttachmentDraftType; try { - if (isImageTypeSupported(fileType) || isHeic(fileType)) { + if (isImageTypeSupported(fileType) || isHeic(fileType, file.name)) { attachment = await handleImageAttachment(file); } else if (isVideoTypeSupported(fileType)) { attachment = await handleVideoAttachment(file);