[tracker-miners/wip/carlosg/backports-3.3: 2/3] tracker-extract: Check field type on IPTC data embedded in TIFFs




commit 3c2457c2fdd0feff181ed93d95f6f44efd3eeb37
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 22 20:08:16 2022 +0200

    tracker-extract: Check field type on IPTC data embedded in TIFFs
    
    The field containing IPTC metadata can come either as TIFF_LONG (32-bit
    ints, endianness dependent), or TIFF_UNDEFINED (a byte string). We currently
    handle everything as TIFF_LONG, which may cause memory corruptions if we
    deal with a file where we must perform endianness swapping and receive
    non-long-aligned data.
    
    Ensure to handle only these 2 types as it is defined for the TIFFTAG_RICHTIFFIPTC
    tag, and only perform byte swapping for non-byte data (i.e. TIFF_LONG).
    
    This is more in line with what other (e.g. ImageMagick) do when dealing with
    byte-swapping and IPTC data.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker/-/issues/364
    
    (cherry-picked from commit 73637bb3e3db3e03abb3d40f5e25c374a7ede6d4)

 src/tracker-extract/tracker-extract-tiff.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 1b67e24dd..06b23ff3a 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <stdint.h>
 
 #include <glib/gstdio.h>
 
@@ -313,15 +314,28 @@ tracker_extract_get_metadata (TrackerExtractInfo  *info,
        uri = g_file_get_uri (file);
 
 #ifdef HAVE_LIBIPTCDATA
-       if (TIFFGetField (image, 
-                         TIFFTAG_RICHTIFFIPTC, 
-                         &iptc_size, 
+       if (TIFFGetField (image,
+                         TIFFTAG_RICHTIFFIPTC,
+                         &iptc_size,
                          &iptc_offset)) {
-               if (TIFFIsByteSwapped(image) != 0) {
-                       TIFFSwabArrayOfLong((uint32*) iptc_offset, 
-                                           (unsigned long) iptc_size);
+               const TIFFField *field;
+               TIFFDataType field_type;
+
+               field = TIFFFieldWithTag (image, TIFFTAG_RICHTIFFIPTC);
+               field_type = TIFFFieldDataType (field);
+
+               if (field_type == TIFF_LONG || field_type == TIFF_UNDEFINED) {
+                       if (field_type == TIFF_LONG) {
+                               if (TIFFIsByteSwapped (image) != 0) {
+                                       TIFFSwabArrayOfLong ((uint32_t *) iptc_offset,
+                                                            (unsigned long) iptc_size);
+                               }
+
+                               iptc_size = 4 * iptc_size;
+                       }
+
+                       id = tracker_iptc_new (iptc_offset, iptc_size, uri);
                }
-               id = tracker_iptc_new (iptc_offset, 4 * iptc_size, uri);
        }
 #endif /* HAVE_LIBIPTCDATA */
 


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