Skip uninteresting APPn markers when searching for EXIF block.
authorDan Fandrich <dan@coneharvesters.com>
Fri, 18 May 2018 08:08:48 +0000 (10:08 +0200)
committerDan Fandrich <dan@coneharvesters.com>
Fri, 18 May 2018 08:11:15 +0000 (10:11 +0200)
libexif rejects images where any APPn marker other than APP0 appears
before APP1.  The EXIF spec says that this is not allowed, but there are
a lot of images where it happens anyway (e.g., from Photoshop).
Patch from Google.

libexif/exif-data.c

index 002af86..23278f5 100644 (file)
@@ -826,8 +826,16 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
                                continue;
                        }
 
-                       /* JPEG_MARKER_APP0 */
-                       if (ds >= 3 && d[0] == JPEG_MARKER_APP0) {
+                       /* JPEG_MARKER_APP1 */
+                       if (ds && d[0] == JPEG_MARKER_APP1)
+                               break;
+
+                       /* Skip irrelevant APP markers. The branch for APP1 must come before this,
+                          otherwise this code block will cause APP1 to be skipped. This code path
+                          is only relevant for files that are nonconformant to the EXIF
+                          specification. For conformant files, the APP1 code path above will be
+                          taken. */
+                       if (ds >= 3 && d[0] >= 0xe0 && d[0] <= 0xef) {  // JPEG_MARKER_APPn
                                d++;
                                ds--;
                                l = (d[0] << 8) | d[1];
@@ -838,10 +846,6 @@ exif_data_load_data (ExifData *data, const unsigned char *d_orig,
                                continue;
                        }
 
-                       /* JPEG_MARKER_APP1 */
-                       if (ds && d[0] == JPEG_MARKER_APP1)
-                               break;
-
                        /* Unknown marker or data. Give up. */
                        exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA,
                                  "ExifData", _("EXIF marker not found."));