Skip to content

fix github issue #122 - correct hemisphere on C2PA GPS longitude/latitude#135

Open
munzzyy wants to merge 1 commit into
guardianproject:mainfrom
munzzyy:fix-c2pa-gps-longitude-hemisphere
Open

fix github issue #122 - correct hemisphere on C2PA GPS longitude/latitude#135
munzzyy wants to merge 1 commit into
guardianproject:mainfrom
munzzyy:fix-c2pa-gps-longitude-hemisphere

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 5, 2026

Copy link
Copy Markdown

Related to #122 - fixes the coordinate-format problem that's still on main after n8fr8's 3400860 (2026-06-26) fixed the missing-GPS symptom from that thread.

The reporter was on 2.6.0-RC-2, which is before C2PAManager.kt existed. That report traces to the old GPSTracker.getLatitudeAsDMS()/getLongitudeAsDMS() (still in the tree under org.witness.proofmode.c2pa, but no longer called from anywhere on main) - both hardcoded a " N"/" W" suffix regardless of the actual sign of the coordinate.

What's still live on main is a different instance of the same underlying problem: exif:GPSLatitude/exif:GPSLongitude in the C2PA metadata assertion get written as a raw signed decimal (it.longitude.toString()). Binary EXIF pairs an unsigned rational with a separate GPSLatitudeRef/GPSLongitudeRef tag, but this is an XMP-style assertion and XMP has no ref tag - the hemisphere has to be encoded directly in the coordinate string as D,M.mmmmmmH (e.g. 6,8.902567W). A plain signed double drops the hemisphere letter, so exiftool/the C2PA verify tool has nothing to go on for which side of the meridian or equator the point is on.

The fix adds toXmpGpsCoordinate(), which converts a signed decimal-degree value into that D,M.mmmmmmH form and picks the hemisphere letter from the sign, then uses it for both latitude and longitude. Formatting uses Locale.US so a comma-decimal device locale can't turn 6,8.902567W into 6,8,902567W and corrupt the field.

I couldn't run the Android instrumentation suite here (no device/emulator, no local JDK/Android SDK in this environment), but I added a JVM unit test (C2PAManagerGpsCoordinateTest) that exercises toXmpGpsCoordinate() directly - the negative-longitude case from the issue (west stays west, no leading minus sign) and the equivalent latitude cases. It lives in src/test, same pattern as ClaimBindingConformanceTest, so it runs on the JVM without a device. I checked the expected DMS values by hand before writing the assertions, but since this repo doesn't run test CI, it'd help if someone ran gradlew :android-libproofmode:testDebugUnitTest locally to confirm.

… longitude/latitude

The original report was on 2.6.0-RC-2, which predates C2PAManager.kt
entirely - that bug was hardcoded "N"/"W" suffixes in the old
GPSTracker.getLatitudeAsDMS()/getLongitudeAsDMS() (org.witness.proofmode.c2pa
package), which slapped on a fixed hemisphere letter no matter the actual
sign. n8fr8's 3400860 already fixed the missing-GPS symptom from that
thread; those DMS methods are unused on main now.

Current main has a related but separate defect: exif:GPSLatitude and
exif:GPSLongitude in the C2PA metadata assertion are written as raw signed
decimal degrees (e.g. -6.148...). That's not a valid XMP GPSCoordinate -
XMP has no separate ref tag like binary EXIF does, so the value has to be
an unsigned "D,M.mmmmmmH" string with the hemisphere folded in. A plain
signed double there leaves hemisphere interpretation up to whatever reads
the field back, which is the same class of bug as the original report,
just living in a different code path.

Added toXmpGpsCoordinate() to build the D,M.mmmmmmH string with the
correct hemisphere letter, and a JVM unit test covering the negative
longitude case plus the equivalent latitude cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant