Handle null exif.tags in getOffsetFromExif (#389)

Handle null exif.tags in getOffsetFromExif

`Object.values()` throws "Cannot convert undefined or null to object"
when `exif.tags` or `exifr` is null/undefined. This occurs when
uploading images that lack EXIF data (e.g., AI-generated images,
screenshots, or graphics). The issue is reproducible on Chrome but
not on Safari, likely due to differences in how each browser's
EXIF parsing pipeline populates these values.

This fix adds nullish coalescing fallbacks (`?? {}`) so that
`Object.values()` always receives a valid object.

* Fix optional chaining in getOffsetFromExif

If `exif` itself is null/undefined,
accessing `exif.tags` would throw before the `??` fallback kicks in.
This commit is contained in:
Ni Z.H. 2026-03-27 06:39:18 +08:00 committed by GitHub
parent da6c6ef09c
commit a8b7c05e0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,8 +16,8 @@ export const getOffsetFromExif = (
exif: ExifData,
exifr: any,
) => (
Object.values(exif.tags as any).find(isValueOffset) ||
Object.values(exifr).find(isValueOffset)
Object.values(exif?.tags ?? {}).find(isValueOffset) ||
Object.values(exifr ?? {}).find(isValueOffset)
) as string | undefined;
export const getDimensionsFromExif = (