Skip to content

Commit 0701835

Browse files
committed
Fix multiple leaks in exif_read_data()
This fixes two leaks related to duplicate tags, as well as a leak of zero-length FMT_(S)BYTE with non-null value. This can show up for MAKERNOTE values where the original length is non-zero, but the first character is a null byte.
1 parent 0d6c244 commit 0701835

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

ext/exif/exif.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,14 +2322,11 @@ static void exif_iif_free(image_info_type *image_info, int section_index) {
23222322
efree(f);
23232323
}
23242324
switch(image_info->info_list[section_index].list[i].format) {
2325+
case TAG_FMT_UNDEFINED:
2326+
case TAG_FMT_STRING:
23252327
case TAG_FMT_SBYTE:
23262328
case TAG_FMT_BYTE:
2327-
/* in contrast to strings bytes do not need to allocate buffer for NULL if length==0 */
2328-
if (image_info->info_list[section_index].list[i].length<1)
2329-
break;
23302329
default:
2331-
case TAG_FMT_UNDEFINED:
2332-
case TAG_FMT_STRING:
23332330
if ((f=image_info->info_list[section_index].list[i].value.s) != NULL) {
23342331
efree(f);
23352332
}
@@ -3543,9 +3540,11 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
35433540
break;
35443541

35453542
case TAG_MAKE:
3543+
EFREE_IF(ImageInfo->make);
35463544
ImageInfo->make = estrndup(value_ptr, byte_count);
35473545
break;
35483546
case TAG_MODEL:
3547+
EFREE_IF(ImageInfo->model);
35493548
ImageInfo->model = estrndup(value_ptr, byte_count);
35503549
break;
35513550

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
OSS-Fuzz: Memory leak for zero-length MAKERNOTE
3+
--FILE--
4+
<?php
5+
6+
@exif_read_data(__DIR__ . '/zero_length_makernote_leak.tiff');
7+
8+
?>
9+
===DONE===
10+
--EXPECT--
11+
===DONE===
164 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)