[web] Handle NaN in the Exif locations

A customer sent us a sample file from the wild where this was the case.
This commit is contained in:
Manav Rathi
2025-01-27 16:02:44 +05:30
parent 34ddeff6bc
commit ac8804a1c1
3 changed files with 12 additions and 5 deletions

View File

@@ -826,6 +826,7 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
const longitude = nullToUndefined(file.metadata.longitude);
if (latitude === undefined || longitude === undefined) return undefined;
if (Number.isNaN(latitude) || Number.isNaN(longitude)) return undefined;
return { latitude, longitude };
};

View File

@@ -51,13 +51,19 @@ export const parseExif = (tags: RawExifTags) => {
/**
* Parse GPS location from the metadata embedded in the file.
*
* - If a location is returned, then both latitude and longitude will be
* defined.
* - NaNs are ignored, and treated as if they are not defined.
*/
const parseLocation = (tags: RawExifTags) => {
const latitude = tags.gps?.Latitude;
const longitude = tags.gps?.Longitude;
return latitude !== undefined && longitude !== undefined
? { latitude, longitude }
: undefined;
if (latitude === undefined || longitude === undefined) return undefined;
if (Number.isNaN(latitude) || Number.isNaN(longitude)) return undefined;
return { latitude, longitude };
};
/**

View File

@@ -8,10 +8,10 @@ export const ensureString = (v: unknown): string => {
};
/**
* Throw an exception if the given value is not a number.
* Throw an exception if the given value is not a number or if it is NaN.
*/
export const ensureNumber = (v: unknown): number => {
if (typeof v != "number")
if (typeof v != "number" || Number.isNaN(v))
throw new Error(`Expected a number, instead found ${String(v)}`);
return v;
};