Skip to content

Commit

Permalink
Fixed bug #77564: Memory leak in exif_process_IFD_TAG
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ramsey authored and nikic committed Feb 12, 2019
1 parent 9222702 commit c429444
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ PHP NEWS
. Fixed bug #77589 (Core dump using parse_ini_string with numeric sections).
(Laruence)

- Exif:
. Fixed bug #77564 (Memory leak in exif_process_IFD_TAG). (Ben Ramsey)

- PDO_OCI:
. Support Oracle Database tracing attributes ACTION, MODULE,
CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter)
Expand Down
4 changes: 4 additions & 0 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,10 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
break;

case TAG_USERCOMMENT:
EFREE_IF(ImageInfo->UserComment);
ImageInfo->UserComment = NULL;
EFREE_IF(ImageInfo->UserCommentEncoding);
ImageInfo->UserCommentEncoding = NULL;
ImageInfo->UserCommentLength = exif_process_user_comment(ImageInfo, &(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr, byte_count);
break;

Expand Down
Binary file added ext/exif/tests/bug77564/bug77564.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions ext/exif/tests/bug77564/bug77564.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug 77564 (Memory leak in exif_process_IFD_TAG)
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--FILE--
<?php
var_dump(exif_read_data(dirname(__FILE__) . '/bug77564.jpg'));
?>
DONE
--EXPECTF--

Warning: exif_read_data(bug77564.jpg): Illegal IFD offset in %sbug77564.php on line %d

Warning: exif_read_data(bug77564.jpg): File structure corrupted in %sbug77564.php on line %d

Warning: exif_read_data(bug77564.jpg): Invalid JPEG file in %sbug77564.php on line %d
bool(false)
DONE

0 comments on commit c429444

Please sign in to comment.