Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix: reject surplus GPS coordinate tokens

HoshinoSuzumiBotd64ea1e7c18b
diff --git a/packages/geocoding/src/index.ts b/packages/geocoding/src/index.ts
index 6848e975..5279f1b9 100644
--- a/packages/geocoding/src/index.ts
+++ b/packages/geocoding/src/index.ts
@@ -247,9 +247,19 @@ export function createGeocodingServices({
// Bound metadata input and validate whole tokens without overlapping
// numeric quantifiers that can cause polynomial regex backtracking.
if (coords.length <= 256) {
- const [lat, lon] = coords.trim().split(/[°,\s]+/)
+ const tokens = coords
+ .trim()
+ .split(/[°,\s]+/)
+ .filter(Boolean)
+ const [lat, lon] = tokens
const decimal = /^[-+]?\d+(?:\.\d*)?$/
- if (lat && lon && decimal.test(lat) && decimal.test(lon)) {
+ if (
+ tokens.length === 2 &&
+ lat &&
+ lon &&
+ decimal.test(lat) &&
+ decimal.test(lon)
+ ) {
latitude = Number(lat)
longitude = Number(lon)
}
diff --git a/tests/geocoding-package.test.ts b/tests/geocoding-package.test.ts
index 2466edc5..d720a445 100644
--- a/tests/geocoding-package.test.ts
+++ b/tests/geocoding-package.test.ts
@@ -78,6 +78,9 @@ test('GPS text parsing accepts decimal pairs and rejects hostile metadata', () =
'9'.repeat(100_000),
'9'.repeat(100_000) + ', 2',
'1.2.3, 4',
+ '48.85, 2.35 W',
+ '48.85, 2.35, 100',
+ '48.85, 2.35 garbage',
'999, 2',
]) {
assert.deepEqual(parseGPSCoordinates({ GPSCoordinates: text }), {})