changeset 30:6fec76de9a8d

Fix some EXIF conversion memory allocation handling.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 May 2017 18:14:31 +0300
parents 1a7b661841c3
children 2326a45dc9f6
files bpgenc.c
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bpgenc.c	Thu May 11 10:05:55 2017 +0300
+++ b/bpgenc.c	Thu May 11 18:14:31 2017 +0300
@@ -1042,7 +1042,7 @@
     {
         const TIFFField *tfd = TIFFFieldWithTag(tif, conv->tag);
         TIFFDataType type = TIFFFieldDataType(tfd);
-        int len = TIFFDataWidth(type);
+        int len = TIFFDataWidth(type), components;
         uint8_t tmp_buf[256], *data;
         char *tmp_str;
         int have;
@@ -1054,13 +1054,18 @@
                 if (have)
                 {
                     data = (uint8_t *) tmp_str;
-                    len = strlen(tmp_str) + 1;
+                    components = strlen(tmp_str) + 1;
                 }
                 break;
 
+            case TIFF_UNDEFINED:
+                have = 0;
+                break;
+
             default:
                 have = TIFFGetField(tif, conv->tag, &tmp_buf);
                 data = tmp_buf;
+                components = 1;
         }
 
         if (have)
@@ -1069,19 +1074,17 @@
             if (entry == NULL)
                 return;
 
-            entry->data = exif_mem_alloc(mem, len);
+            entry->data = exif_mem_alloc(mem, len * components);
             if (entry->data == NULL)
                 return;
 
-            memcpy(entry->data, data, len);
+            memcpy(entry->data, data, len * components);
             entry->size = len;
             entry->tag = conv->tag;
-            entry->components = len;
+            entry->components = components;
             entry->format = type;
 
             exif_content_add_entry(exif->ifd[conv->ifd], entry);
-            exif_mem_unref(mem);
-            exif_entry_unref(entry);
             (*added)++;
         }
     }
@@ -1117,6 +1120,7 @@
     toff_t tmp_offs;
     ExifMem *exif_mem = NULL;
     ExifData *exif = NULL;
+    int added = 0;
 #endif
 
     // Set warning handler to silence dubious warnings about unknown fields
@@ -1329,7 +1333,6 @@
     exif_data_set_data_type(exif, EXIF_DATA_TYPE_COMPRESSED);
     exif_data_set_byte_order(exif, EXIF_BYTE_ORDER_INTEL);
 
-    int added = 0;
     tiff_tags_convert(tif, tiff_tag_convert_table, exif_mem, exif, &added);
 
     if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &tmp_offs) &&