Skip to content

Commit c429444

Browse files
ramseynikic
authored andcommitted
Fixed bug #77564: Memory leak in exif_process_IFD_TAG
The memory leak occurs when more than one UserComment tag is present in the EXIF data. It's still considered corrupt EXIF data, but this ensures the memory is freed before trying to set to already allocated memory.
1 parent 9222702 commit c429444

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #77589 (Core dump using parse_ini_string with numeric sections).
77
(Laruence)
88

9+
- Exif:
10+
. Fixed bug #77564 (Memory leak in exif_process_IFD_TAG). (Ben Ramsey)
11+
912
- PDO_OCI:
1013
. Support Oracle Database tracing attributes ACTION, MODULE,
1114
CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter)

ext/exif/exif.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,10 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
34053405
break;
34063406

34073407
case TAG_USERCOMMENT:
3408+
EFREE_IF(ImageInfo->UserComment);
3409+
ImageInfo->UserComment = NULL;
3410+
EFREE_IF(ImageInfo->UserCommentEncoding);
3411+
ImageInfo->UserCommentEncoding = NULL;
34083412
ImageInfo->UserCommentLength = exif_process_user_comment(ImageInfo, &(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr, byte_count);
34093413
break;
34103414

ext/exif/tests/bug77564/bug77564.jpg

73 Bytes
Loading

ext/exif/tests/bug77564/bug77564.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug 77564 (Memory leak in exif_process_IFD_TAG)
3+
--SKIPIF--
4+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
5+
--FILE--
6+
<?php
7+
var_dump(exif_read_data(dirname(__FILE__) . '/bug77564.jpg'));
8+
?>
9+
DONE
10+
--EXPECTF--
11+
12+
Warning: exif_read_data(bug77564.jpg): Illegal IFD offset in %sbug77564.php on line %d
13+
14+
Warning: exif_read_data(bug77564.jpg): File structure corrupted in %sbug77564.php on line %d
15+
16+
Warning: exif_read_data(bug77564.jpg): Invalid JPEG file in %sbug77564.php on line %d
17+
bool(false)
18+
DONE

0 commit comments

Comments
 (0)