summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2019-03-03 22:20:42 -0800
committerChristoph M. Becker <cmbecker69@gmx.de>2019-03-04 13:18:32 +0100
commite0a7e0670ab6172eef0a2bd424169b11dced1071 (patch)
treee23021282fc8ee7eb9233dd711ee95726d7c601a
parent08daf96c92f1092fb275d5d26e57e2a61a9cb831 (diff)
downloadphp-git-e0a7e0670ab6172eef0a2bd424169b11dced1071.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Update NEWS Fix test error message Fix bug #77563 - Uninitialized read in exif_process_IFD_in_MAKERNOTE Fix bug #77540 - Invalid Read on exif_process_SOFn Fix integer overflows on 32-bits Fix #77431 SplFileInfo::__construct() accepts NUL bytes Fix bug #77396 - Null Pointer Dereference in phar_create_or_parse_filename (cherry picked from commit e3f7c352dce5c63d75976f428f7ff9a160c2be4f)
-rw-r--r--ext/exif/exif.c27
-rw-r--r--ext/exif/tests/bug77540.jpgbin0 -> 91 bytes
-rw-r--r--ext/exif/tests/bug77540.phpt16
-rw-r--r--ext/exif/tests/bug77563.jpgbin0 -> 63 bytes
-rw-r--r--ext/exif/tests/bug77563.phpt16
-rw-r--r--ext/phar/phar.c3
-rw-r--r--ext/phar/tests/bug77396.phpt15
-rw-r--r--ext/spl/spl_directory.c2
-rw-r--r--ext/spl/tests/bug77431.phpt9
9 files changed, 77 insertions, 11 deletions
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index 6d287ccc1e..1b7d0cc462 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -3125,7 +3125,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
break;
}
- if (maker_note->offset >= value_len) {
+ if (value_len < 2 || maker_note->offset >= value_len - 1) {
/* Do not go past the value end */
exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "IFD data too short: 0x%04X offset 0x%04X", value_len, maker_note->offset);
return FALSE;
@@ -3180,6 +3180,7 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
#endif
default:
case MN_OFFSET_NORMAL:
+ data_len = value_len;
break;
}
@@ -3903,7 +3904,7 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
return FALSE;
marker = c;
length = php_jpg_get16(data+pos);
- if (pos+length>=ImageInfo->Thumbnail.size) {
+ if (length > ImageInfo->Thumbnail.size || pos >= ImageInfo->Thumbnail.size - length) {
return FALSE;
}
#ifdef EXIF_DEBUG
@@ -3924,6 +3925,10 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
case M_SOF14:
case M_SOF15:
/* handle SOFn block */
+ if (length < 8 || ImageInfo->Thumbnail.size - 8 < pos) {
+ /* exif_process_SOFn needs 8 bytes */
+ return FALSE;
+ }
exif_process_SOFn(data+pos, marker, &sof_info);
ImageInfo->Thumbnail.height = sof_info.height;
ImageInfo->Thumbnail.width = sof_info.width;
@@ -3961,10 +3966,10 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
tag_table_type tag_table = exif_get_tag_table(section_index);
if (ImageInfo->ifd_nesting_level > MAX_IFD_NESTING_LEVEL) {
- return FALSE;
- }
+ return FALSE;
+ }
- if (ImageInfo->FileSize >= dir_offset+2) {
+ if (ImageInfo->FileSize >= 2 && ImageInfo->FileSize - 2 >= dir_offset) {
sn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);
#ifdef EXIF_DEBUG
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, 2);
@@ -3972,8 +3977,8 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
php_stream_seek(ImageInfo->infile, dir_offset, SEEK_SET); /* we do not know the order of sections */
php_stream_read(ImageInfo->infile, (char*)ImageInfo->file.list[sn].data, 2);
num_entries = php_ifd_get16u(ImageInfo->file.list[sn].data, ImageInfo->motorola_intel);
- dir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;
- if (ImageInfo->FileSize >= dir_offset+dir_size) {
+ dir_size = 2/*num dir entries*/ +12/*length of entry*/*(size_t)num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;
+ if (ImageInfo->FileSize >= dir_size && ImageInfo->FileSize - dir_size >= dir_offset) {
#ifdef EXIF_DEBUG
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X), IFD entries(%d)", ImageInfo->FileSize, dir_offset+2, dir_size-2, num_entries);
#endif
@@ -4056,9 +4061,9 @@ static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offse
}
}
}
- if (ImageInfo->FileSize >= dir_offset + ImageInfo->file.list[sn].size) {
+ if (ImageInfo->FileSize >= ImageInfo->file.list[sn].size && ImageInfo->FileSize - ImageInfo->file.list[sn].size >= dir_offset) {
if (ifd_size > dir_size) {
- if (dir_offset + ifd_size > ImageInfo->FileSize) {
+ if (ImageInfo->FileSize < ifd_size || dir_offset > ImageInfo->FileSize - ifd_size) {
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error in TIFF: filesize(x%04X) less than size of IFD(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, ifd_size);
return FALSE;
}
@@ -4655,7 +4660,9 @@ PHP_FUNCTION(exif_thumbnail)
ZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);
if (arg_c >= 3) {
if (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
- exif_scan_thumbnail(&ImageInfo);
+ if (!exif_scan_thumbnail(&ImageInfo)) {
+ ImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;
+ }
}
zval_ptr_dtor(z_width);
zval_ptr_dtor(z_height);
diff --git a/ext/exif/tests/bug77540.jpg b/ext/exif/tests/bug77540.jpg
new file mode 100644
index 0000000000..559022db0e
--- /dev/null
+++ b/ext/exif/tests/bug77540.jpg
Binary files differ
diff --git a/ext/exif/tests/bug77540.phpt b/ext/exif/tests/bug77540.phpt
new file mode 100644
index 0000000000..a284e1f263
--- /dev/null
+++ b/ext/exif/tests/bug77540.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug 77540 (Invalid Read on exif_process_SOFn)
+--SKIPIF--
+<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
+--FILE--
+<?php
+$width = $height = 42;
+$s = exif_thumbnail(__DIR__."/bug77540.jpg", $width, $height);
+echo "Width ".$width."\n";
+echo "Height ".$height."\n";
+?>
+DONE
+--EXPECTF--
+Width 0
+Height 0
+DONE \ No newline at end of file
diff --git a/ext/exif/tests/bug77563.jpg b/ext/exif/tests/bug77563.jpg
new file mode 100644
index 0000000000..d6280151f0
--- /dev/null
+++ b/ext/exif/tests/bug77563.jpg
Binary files differ
diff --git a/ext/exif/tests/bug77563.phpt b/ext/exif/tests/bug77563.phpt
new file mode 100644
index 0000000000..9e7ccc768b
--- /dev/null
+++ b/ext/exif/tests/bug77563.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug 77563 (Uninitialized read in exif_process_IFD_in_MAKERNOTE)
+--SKIPIF--
+<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
+--FILE--
+<?php
+$s = exif_thumbnail(__DIR__."/bug77563.jpg");
+?>
+DONE
+--EXPECTF--
+Warning: exif_thumbnail(bug77563.jpg): IFD data too short: 0x0009 offset 0x0008 in %s/bug77563.php on line %d
+
+Warning: exif_thumbnail(bug77563.jpg): File structure corrupted in %s/bug77563.php on line %d
+
+Warning: exif_thumbnail(bug77563.jpg): Invalid JPEG file in %s/bug77563.php on line %d
+DONE \ No newline at end of file
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 812720a011..80ec059b68 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -1403,6 +1403,9 @@ int phar_create_or_parse_filename(char *fname, size_t fname_len, char *alias, si
/* set up our manifest */
mydata = ecalloc(1, sizeof(phar_archive_data));
mydata->fname = expand_filepath(fname, NULL);
+ if (mydata->fname == NULL) {
+ return FAILURE;
+ }
fname_len = strlen(mydata->fname);
#ifdef PHP_WIN32
phar_unixify_path_separators(mydata->fname, fname_len);
diff --git a/ext/phar/tests/bug77396.phpt b/ext/phar/tests/bug77396.phpt
new file mode 100644
index 0000000000..f7a2a2f026
--- /dev/null
+++ b/ext/phar/tests/bug77396.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #77396 Relative filename exceeding maximum path length causes null pointer dereference.
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$path = '../' . str_repeat("x", PHP_MAXPATHLEN) . '.tar';
+$phar = new PharData($path);
+?>
+--EXPECTF--
+Fatal error: Uncaught UnexpectedValueException: Phar creation or opening failed in %s/bug77396.php:%d
+Stack trace:
+#0 %s/bug77396.php(%d): PharData->__construct(%s)
+#1 {main}
+ thrown in %s/bug77396.php on line %d
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 0f0da14c15..946e1cde7d 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -1133,7 +1133,7 @@ SPL_METHOD(SplFileInfo, __construct)
char *path;
size_t len;
- if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p", &path, &len) == FAILURE) {
return;
}
diff --git a/ext/spl/tests/bug77431.phpt b/ext/spl/tests/bug77431.phpt
new file mode 100644
index 0000000000..eb1ca96b75
--- /dev/null
+++ b/ext/spl/tests/bug77431.phpt
@@ -0,0 +1,9 @@
+--TEST--
+Bug #77431 (SplFileInfo::__construct() accepts NUL bytes)
+--FILE--
+<?php
+new SplFileInfo("bad\0good");
+?>
+--EXPECTF--
+Fatal error: Uncaught TypeError: SplFileInfo::__construct() expects parameter 1 to be a valid path, string given in %s:%d
+Stack trace:%A \ No newline at end of file