From 91fedb08bcac8235947d686b747e0a81fd28e230 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sat, 26 Jul 2025 20:52:19 +0200 Subject: [PATCH] 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) --- includes/media/Exif.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/media/Exif.php b/includes/media/Exif.php index 05c4c35ea31..d25574a01fe 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -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; }