From 895dd20b1123ec7df4760f0e28084ae87a6e95d1 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 17 Apr 2024 19:14:10 +0530 Subject: [PATCH 1/2] fix: wrong attachment corrupt alert for pdf. Signed-off-by: Krishna Gupta --- src/components/AttachmentPicker/index.native.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index ef4d7e3e4064..865e79a8cd37 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -238,8 +238,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s const validateAndCompleteAttachmentSelection = useCallback( (fileData: FileResponse) => { // Check if the file dimensions indicate corruption - // The width/height for corrupt file is -1 on android native and 0 on ios native - if (!fileData.width || !fileData.height || (fileData.width <= 0 && fileData.height <= 0)) { + if (fileData.width === -1 || fileData.height === -1) { showImageCorruptionAlert(); return Promise.resolve(); } @@ -287,6 +286,10 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s if (fileDataName && Str.isImage(fileDataName)) { ImageSize.getSize(fileDataUri) .then(({width, height}) => { + // The width/height for corrupt file is -1 on android native and 0 on ios native + if (width <= 0 || height <= 0) { + throw new Error('Image dimensions are invalid.'); + } fileDataObject.width = width; fileDataObject.height = height; validateAndCompleteAttachmentSelection(fileDataObject); From 484344fc4d8672d434f407477bb8b5012416a600 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 17 Apr 2024 22:43:37 +0530 Subject: [PATCH 2/2] placed validating the dimensions in one place. Signed-off-by: Krishna Gupta --- src/components/AttachmentPicker/index.native.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index 865e79a8cd37..5e54458da001 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -238,7 +238,9 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s const validateAndCompleteAttachmentSelection = useCallback( (fileData: FileResponse) => { // Check if the file dimensions indicate corruption - if (fileData.width === -1 || fileData.height === -1) { + // The width/height for a corrupted file is -1 on android native and 0 on ios native + // We must check only numeric values because the width/height can be undefined for non-image files + if ((typeof fileData.width === 'number' && fileData.width <= 0) || (typeof fileData.height === 'number' && fileData.height <= 0)) { showImageCorruptionAlert(); return Promise.resolve(); } @@ -286,10 +288,6 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s if (fileDataName && Str.isImage(fileDataName)) { ImageSize.getSize(fileDataUri) .then(({width, height}) => { - // The width/height for corrupt file is -1 on android native and 0 on ios native - if (width <= 0 || height <= 0) { - throw new Error('Image dimensions are invalid.'); - } fileDataObject.width = width; fileDataObject.height = height; validateAndCompleteAttachmentSelection(fileDataObject);