Skip to content

Commit 284fb08

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix #77919: Potential UAF in Phar RSHUTDOWN Update NEWS Fix bug #78256 (heap-buffer-overflow on exif_process_user_comment) Fix bug #78222 (heap-buffer-overflow on exif_scan_thumbnail)
2 parents dc7aa22 + cd1101e commit 284fb08

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

ext/exif/exif.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,11 +3054,11 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
30543054
/* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
30553055
* since we have no encoding support for the BOM yet we skip that.
30563056
*/
3057-
if (!memcmp(szValuePtr, "\xFE\xFF", 2)) {
3057+
if (ByteCount >=2 && !memcmp(szValuePtr, "\xFE\xFF", 2)) {
30583058
decode = "UCS-2BE";
30593059
szValuePtr = szValuePtr+2;
30603060
ByteCount -= 2;
3061-
} else if (!memcmp(szValuePtr, "\xFF\xFE", 2)) {
3061+
} else if (ByteCount >=2 && !memcmp(szValuePtr, "\xFF\xFE", 2)) {
30623062
decode = "UCS-2LE";
30633063
szValuePtr = szValuePtr+2;
30643064
ByteCount -= 2;
@@ -3933,7 +3933,7 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
39333933
size_t length=2, pos=0;
39343934
jpeg_sof_info sof_info;
39353935

3936-
if (!data) {
3936+
if (!data || ImageInfo->Thumbnail.size < 4) {
39373937
return FALSE; /* nothing to do here */
39383938
}
39393939
if (memcmp(data, "\xFF\xD8\xFF", 3)) {

ext/exif/tests/bug78222.jpg

91 Bytes
Loading

ext/exif/tests/bug78222.phpt

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

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

ext/phar/phar_object.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
20372037
char *newname = NULL, *newpath = NULL;
20382038
zval ret, arg1;
20392039
zend_class_entry *ce;
2040-
char *error;
2040+
char *error = NULL;
20412041
const char *pcr_error;
20422042
int ext_len = ext ? strlen(ext) : 0;
20432043
size_t new_len, oldname_len, phar_ext_len;
@@ -2252,6 +2252,8 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
22522252
phar_flush(phar, 0, 0, 1, &error);
22532253

22542254
if (error) {
2255+
zend_hash_str_del(&(PHAR_G(phar_fname_map)), newpath, phar->fname_len);
2256+
*sphar = NULL;
22552257
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s", error);
22562258
efree(error);
22572259
efree(oldpath);

ext/phar/tests/bug71488.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ DONE
1515
?>
1616
--EXPECTF--
1717
Fatal error: Uncaught BadMethodCallException: tar-based phar "%s/bug71488.test" cannot be created, link "%s" is too long for format in %sbug71488.php:%d
18-
Stack trace:%A
18+
Stack trace:
19+
#0 %s(%d): PharData->decompress('test')
20+
#1 {main}
21+
thrown in %s on line %d

0 commit comments

Comments
 (0)