From 480fa07b5cea4671174a530e00e069becde799be Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Thu, 7 Mar 2024 13:52:01 +0100 Subject: [PATCH 1/2] Declare GPSLatitude and GPSLongitude as unsigned rational Fixes code fault where they were instead declared as `TYPE_RATIONAL` (i.e. signed rational). See https://gitlab.e.foundation/e/backlog/-/issues/7599#note_511031. --- .../src/com/android/gallery3d/exif/ExifInterface.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java index 21422095e..fb2368bd7 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java @@ -2283,9 +2283,9 @@ public class ExifInterface { mTagInfo.put(ExifInterface.TAG_GPS_LONGITUDE_REF, gpsFlags | ExifTag.TYPE_ASCII << 16 | 2); mTagInfo.put(ExifInterface.TAG_GPS_LATITUDE, - gpsFlags | ExifTag.TYPE_RATIONAL << 16 | 3); + gpsFlags | ExifTag.TYPE_UNSIGNED_RATIONAL << 16 | 3); mTagInfo.put(ExifInterface.TAG_GPS_LONGITUDE, - gpsFlags | ExifTag.TYPE_RATIONAL << 16 | 3); + gpsFlags | ExifTag.TYPE_UNSIGNED_RATIONAL << 16 | 3); mTagInfo.put(ExifInterface.TAG_GPS_ALTITUDE_REF, gpsFlags | ExifTag.TYPE_UNSIGNED_BYTE << 16 | 1); mTagInfo.put(ExifInterface.TAG_GPS_ALTITUDE, -- GitLab From e31888652dfc819abc610b938d3edac85420d39a Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 12 Mar 2024 12:50:57 +0100 Subject: [PATCH 2/2] Crop of `\0` from Strings in GPS conversion Per documentation, ExifInterface returns null-terminated strings. This leads to a bug in `convertLatOrLongToDouble()` when "S\0" instead of "S" (like documented) is provided. --- .../src/com/android/gallery3d/exif/ExifInterface.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java index fb2368bd7..e74c84dff 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java @@ -1942,12 +1942,13 @@ public class ExifInterface { Rational[] longitude = getTagRationalValues(TAG_GPS_LONGITUDE); String longitudeRef = getTagStringValue(TAG_GPS_LONGITUDE_REF); if (latitude == null || longitude == null || latitudeRef == null || longitudeRef == null - || latitude.length < 3 || longitude.length < 3) { + || latitude.length < 3 || longitude.length < 3 + || latitudeRef.length() != 2 || longitudeRef.length() != 2) { return null; } double[] latLon = new double[2]; - latLon[0] = convertLatOrLongToDouble(latitude, latitudeRef); - latLon[1] = convertLatOrLongToDouble(longitude, longitudeRef); + latLon[0] = convertLatOrLongToDouble(latitude, latitudeRef.substring(0, 1)); + latLon[1] = convertLatOrLongToDouble(longitude, longitudeRef.substring(0, 1)); return latLon; } -- GitLab