comparison bpgenc.c @ 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 38ae4a231581
comparison
equal deleted inserted replaced
29:1a7b661841c3 30:6fec76de9a8d
1040 1040
1041 for (conv = table; conv->tag != 0 && conv->name != NULL; conv++) 1041 for (conv = table; conv->tag != 0 && conv->name != NULL; conv++)
1042 { 1042 {
1043 const TIFFField *tfd = TIFFFieldWithTag(tif, conv->tag); 1043 const TIFFField *tfd = TIFFFieldWithTag(tif, conv->tag);
1044 TIFFDataType type = TIFFFieldDataType(tfd); 1044 TIFFDataType type = TIFFFieldDataType(tfd);
1045 int len = TIFFDataWidth(type); 1045 int len = TIFFDataWidth(type), components;
1046 uint8_t tmp_buf[256], *data; 1046 uint8_t tmp_buf[256], *data;
1047 char *tmp_str; 1047 char *tmp_str;
1048 int have; 1048 int have;
1049 1049
1050 switch (type) 1050 switch (type)
1052 case TIFF_ASCII: 1052 case TIFF_ASCII:
1053 have = TIFFGetField(tif, conv->tag, &tmp_str) && tmp_str != NULL; 1053 have = TIFFGetField(tif, conv->tag, &tmp_str) && tmp_str != NULL;
1054 if (have) 1054 if (have)
1055 { 1055 {
1056 data = (uint8_t *) tmp_str; 1056 data = (uint8_t *) tmp_str;
1057 len = strlen(tmp_str) + 1; 1057 components = strlen(tmp_str) + 1;
1058 } 1058 }
1059 break;
1060
1061 case TIFF_UNDEFINED:
1062 have = 0;
1059 break; 1063 break;
1060 1064
1061 default: 1065 default:
1062 have = TIFFGetField(tif, conv->tag, &tmp_buf); 1066 have = TIFFGetField(tif, conv->tag, &tmp_buf);
1063 data = tmp_buf; 1067 data = tmp_buf;
1068 components = 1;
1064 } 1069 }
1065 1070
1066 if (have) 1071 if (have)
1067 { 1072 {
1068 ExifEntry *entry = exif_entry_new_mem(mem); 1073 ExifEntry *entry = exif_entry_new_mem(mem);
1069 if (entry == NULL) 1074 if (entry == NULL)
1070 return; 1075 return;
1071 1076
1072 entry->data = exif_mem_alloc(mem, len); 1077 entry->data = exif_mem_alloc(mem, len * components);
1073 if (entry->data == NULL) 1078 if (entry->data == NULL)
1074 return; 1079 return;
1075 1080
1076 memcpy(entry->data, data, len); 1081 memcpy(entry->data, data, len * components);
1077 entry->size = len; 1082 entry->size = len;
1078 entry->tag = conv->tag; 1083 entry->tag = conv->tag;
1079 entry->components = len; 1084 entry->components = components;
1080 entry->format = type; 1085 entry->format = type;
1081 1086
1082 exif_content_add_entry(exif->ifd[conv->ifd], entry); 1087 exif_content_add_entry(exif->ifd[conv->ifd], entry);
1083 exif_mem_unref(mem);
1084 exif_entry_unref(entry);
1085 (*added)++; 1088 (*added)++;
1086 } 1089 }
1087 } 1090 }
1088 } 1091 }
1089 #endif 1092 #endif
1115 RGBConvertFunc *convert_func; 1118 RGBConvertFunc *convert_func;
1116 #ifdef HAVE_LIBEXIF 1119 #ifdef HAVE_LIBEXIF
1117 toff_t tmp_offs; 1120 toff_t tmp_offs;
1118 ExifMem *exif_mem = NULL; 1121 ExifMem *exif_mem = NULL;
1119 ExifData *exif = NULL; 1122 ExifData *exif = NULL;
1123 int added = 0;
1120 #endif 1124 #endif
1121 1125
1122 // Set warning handler to silence dubious warnings about unknown fields 1126 // Set warning handler to silence dubious warnings about unknown fields
1123 TIFFSetWarningHandler(tiff_warning_handler); 1127 TIFFSetWarningHandler(tiff_warning_handler);
1124 1128
1327 1331
1328 exif_data_set_option(exif, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION); 1332 exif_data_set_option(exif, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
1329 exif_data_set_data_type(exif, EXIF_DATA_TYPE_COMPRESSED); 1333 exif_data_set_data_type(exif, EXIF_DATA_TYPE_COMPRESSED);
1330 exif_data_set_byte_order(exif, EXIF_BYTE_ORDER_INTEL); 1334 exif_data_set_byte_order(exif, EXIF_BYTE_ORDER_INTEL);
1331 1335
1332 int added = 0;
1333 tiff_tags_convert(tif, tiff_tag_convert_table, exif_mem, exif, &added); 1336 tiff_tags_convert(tif, tiff_tag_convert_table, exif_mem, exif, &added);
1334 1337
1335 if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &tmp_offs) && 1338 if (TIFFGetField(tif, TIFFTAG_EXIFIFD, &tmp_offs) &&
1336 TIFFReadEXIFDirectory(tif, tmp_offs)) 1339 TIFFReadEXIFDirectory(tif, tmp_offs))
1337 { 1340 {