Skip to content

Commit aeb6d13

Browse files
committed
Fix bug #78256 (heap-buffer-overflow on exif_process_user_comment)
1 parent dea2989 commit aeb6d13

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

ext/exif/exif.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,7 +2619,7 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
26192619
{
26202620
int a;
26212621
char *decode;
2622-
size_t len;;
2622+
size_t len;
26232623

26242624
*pszEncoding = NULL;
26252625
/* Copy the comment */
@@ -2632,11 +2632,11 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
26322632
/* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
26332633
* since we have no encoding support for the BOM yet we skip that.
26342634
*/
2635-
if (!memcmp(szValuePtr, "\xFE\xFF", 2)) {
2635+
if (ByteCount >=2 && !memcmp(szValuePtr, "\xFE\xFF", 2)) {
26362636
decode = "UCS-2BE";
26372637
szValuePtr = szValuePtr+2;
26382638
ByteCount -= 2;
2639-
} else if (!memcmp(szValuePtr, "\xFF\xFE", 2)) {
2639+
} else if (ByteCount >=2 && !memcmp(szValuePtr, "\xFF\xFE", 2)) {
26402640
decode = "UCS-2LE";
26412641
szValuePtr = szValuePtr+2;
26422642
ByteCount -= 2;

ext/exif/tests/bug78256.jpg

69 Bytes
Loading

ext/exif/tests/bug78256.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #78256 (heap-buffer-overflow on exif_process_user_comment)
3+
--SKIPIF--
4+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
5+
--FILE--
6+
<?php
7+
@exif_read_data(__DIR__."/bug78256.jpg", 'COMMENT', FALSE, TRUE);
8+
?>
9+
DONE
10+
--EXPECTF--
11+
DONE

0 commit comments

Comments
 (0)