[tracker-miners: 1/2] libtracker-extract: Be more robust with files with duff GPS data




commit 6f40bd5e51c1ee1437f09c6ee69e285bb2e35b0b
Author: Andrew Clayton <andrew digital-domain net>
Date:   Fri Feb 26 17:27:16 2021 +0000

    libtracker-extract: Be more robust with files with duff GPS data
    
    I have various image files that were created with a slide scanner. for
    whatever reason the scanner has put in some bogus GPS data, here is an
    example of that data output from exiv2
    
      0x8825 Image        GPSTag                  Long        1  42674
      0x0000 GPSInfo      GPSVersionID            Byte        4  2 2 0 0
      0x0001 GPSInfo      GPSLatitudeRef          Ascii       4  N
      0x0002 GPSInfo      GPSLatitude             Rational    3  0/1 0/1 0/1
      0x0003 GPSInfo      GPSLongitudeRef         Ascii       4  E
      0x0004 GPSInfo      GPSLongitude            Rational    3  0/1 0/1 0/1
      0x0005 GPSInfo      GPSAltitudeRef          Byte        4  0 0 0 0
      0x0006 GPSInfo      GPSAltitude             Rational    1  0/1
      0x0007 GPSInfo      GPSTimeStamp            Rational    3  0/1 0/1 0/1
      0x001d GPSInfo      GPSDateStamp            Ascii      12  2011:01:01 0
    
    which results in the following
    
      (tracker-extract-3:22459): Tracker-ERROR **: 22:30:02.545: Invalid GPS Ref entry!
    
    and the process promptly core dumps, this happens every time I login...
    
    Tracing with GDB, this seems to trip up the
    
      if (refentry->format == EXIF_FORMAT_ASCII && (refentry->size == 2)) {
    
    check in src/libtracker-extract/tracker-exif.c::get_gps_coordinate()
    when trying to get the GPS latitude data with refentry->size being 4 in
    this case and thus falling through to a g_error() call.
    
    refentry->size is the size of the GPSLatitudeRef field above which you
    can see is 4 chars wide, it should only be two.
    
    We can try to handle this case without just aborting by changing the
    refentry->size check to be > 0. Not sure if it would be possible to have
    a 0 sized GPSLatitudeRef/GPSLongitudeRef but just to be on the safe
    side. We could make it >= 2, but we don't need it to be nul terminated
    and this might save us some unnecessary aborts.

 src/libtracker-extract/tracker-exif.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-exif.c b/src/libtracker-extract/tracker-exif.c
index 86c1aa0c4..995456856 100644
--- a/src/libtracker-extract/tracker-exif.c
+++ b/src/libtracker-extract/tracker-exif.c
@@ -331,13 +331,16 @@ get_gps_coordinate (ExifData *exif,
                                (gdouble) minutes.numerator / (minutes.denominator * 60) +
                                (gdouble) seconds.numerator / (seconds.denominator * 60 * 60);
 
-                       if (refentry->format == EXIF_FORMAT_ASCII && (refentry->size == 2)) {
-                               // following Exif Version 2.2 specs
-                               if (refentry->data[0] == 'S' || refentry->data[0] == 'W') {
-                                       f = -1 * f;
-                               }
-                       } else {
-                               g_error("Invalid GPS Ref entry!");
+                       if (refentry->format != EXIF_FORMAT_ASCII || refentry->size < 2) {
+                               g_debug ("Invalid format/size for GPS ref entry");
+                               return NULL;
+                       }
+
+                       /* following Exif Version 2.2 specs */
+                       if (refentry->data[0] == 'S' || refentry->data[0] == 'W') {
+                               f = -1 * f;
+                       } else if (refentry->data[0] != 'N' && refentry->data[0] != 'E') {
+                               g_debug ("Invalid GPS Ref entry content");
                                return NULL;
                        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]