Exif: Handle malformed gps tags

- Handle GPS tags with decimal rational number instead of array of dms
  rationals
- Mod the decimal values
- Increase validation on GPS tag format

Bug: T386208
Change-Id: Ief823af317bbb01b4a05e34b1d189ce1deaa1f33
(cherry picked from commit 55ffc43a596c0547986322ffe679d37daa921be7)
This commit is contained in:
Derk-Jan Hartman 2025-07-26 20:52:19 +02:00 committed by Reedy
parent bce244403c
commit 91fedb08bc

View file

@ -647,15 +647,21 @@ class Exif {
$dir = $this->mFilteredExifData[$prop . 'Ref'] ?? null;
$res = false;
if ( $loc !== null && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' ) ) {
[ $num, $denom ] = explode( '/', $loc[0], 2 );
$res = (int)$num / (int)$denom;
[ $num, $denom ] = explode( '/', $loc[1], 2 );
$res += ( (int)$num / (int)$denom ) * ( 1 / 60 );
[ $num, $denom ] = explode( '/', $loc[2], 2 );
$res += ( (int)$num / (int)$denom ) * ( 1 / 3600 );
if ( $loc !== null && in_array( $dir, [ 'N', 'S', 'E', 'W' ] ) ) {
if ( is_array( $loc ) && count( $loc ) === 3 ) {
[ $num, $denom ] = explode( '/', $loc[0], 2 );
$res = (int)$num / (int)$denom;
[ $num, $denom ] = explode( '/', $loc[1], 2 );
$res += ( (int)$num / (int)$denom ) * ( 1 / 60 );
[ $num, $denom ] = explode( '/', $loc[2], 2 );
$res += ( (int)$num / (int)$denom ) * ( 1 / 3600 );
} elseif ( is_string( $loc ) ) {
// This is non-standard, but occurs in the wild (T386208)
[ $num, $denom ] = explode( '/', $loc, 2 );
$res = (int)$num / (int)$denom;
}
if ( $dir === 'S' || $dir === 'W' ) {
if ( $res && ( $dir === 'S' || $dir === 'W' ) ) {
// make negative
$res *= -1;
}