Skip to content

Commit

Permalink
Fix bug #78256 (heap-buffer-overflow on exif_process_user_comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jul 29, 2019
1 parent dea2989 commit aeb6d13
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
{
int a;
char *decode;
size_t len;;
size_t len;

*pszEncoding = NULL;
/* Copy the comment */
Expand All @@ -2632,11 +2632,11 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
/* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
* since we have no encoding support for the BOM yet we skip that.
*/
if (!memcmp(szValuePtr, "\xFE\xFF", 2)) {
if (ByteCount >=2 && !memcmp(szValuePtr, "\xFE\xFF", 2)) {
decode = "UCS-2BE";
szValuePtr = szValuePtr+2;
ByteCount -= 2;
} else if (!memcmp(szValuePtr, "\xFF\xFE", 2)) {
} else if (ByteCount >=2 && !memcmp(szValuePtr, "\xFF\xFE", 2)) {
decode = "UCS-2LE";
szValuePtr = szValuePtr+2;
ByteCount -= 2;
Expand Down
Binary file added ext/exif/tests/bug78256.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ext/exif/tests/bug78256.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Bug #78256 (heap-buffer-overflow on exif_process_user_comment)
--SKIPIF--
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
--FILE--
<?php
@exif_read_data(__DIR__."/bug78256.jpg", 'COMMENT', FALSE, TRUE);
?>
DONE
--EXPECTF--
DONE

0 comments on commit aeb6d13

Please sign in to comment.