[tracker-miners/wip/carlosg/tiff-iptc] tracker-extract: Check field type on IPTC data embedded in TIFFs
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/tiff-iptc] tracker-extract: Check field type on IPTC data embedded in TIFFs
- Date: Sun, 22 May 2022 18:28:17 +0000 (UTC)
commit 9735954d926d26bda219942e081dce4efc495727
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
src/tracker-extract/tracker-extract-tiff.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 1b67e24dd..d023b95f3 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -313,15 +313,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]