com php-src: Fix bug #77540 - Invalid Read on exif_process_ SOFn: ext/exif/exif.c ext/exif/tests/bug77540 .jpg ext/exif/tests/bug77540.phpt
| From: | Stanislav Malyshev | Date: | Mon, 04 Mar 2019 07:34:00 +0000 |
| Subject: | com php-src: Fix bug #77540 - Invalid Read on exif_process_ SOFn: ext/exif/exif.c ext/exif/tests/bug77540 .jpg ext/exif/tests/bug77540.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104971@lists.php.net to get a copy of this message | ||
Commit: 30d2b94a2e88021b77b07149e1f4438662ca8e5e
Author: Stanislav Malyshev <stas@php.net> Sat, 2 Mar 2019 13:38:00 -0800
Parents: 46e79c93518365c7bda894bc512f4be282a29d48
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=30d2b94a2e88021b77b07149e1f4438662ca8e5e
Log:
Fix bug #77540 - Invalid Read on exif_process_SOFn
Bugs:
https://bugs.php.net/77540
Changed paths:
M ext/exif/exif.c
A ext/exif/tests/bug77540.jpg
A ext/exif/tests/bug77540.phpt
Diff:
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index 4f2f660..8ed9c85 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -3902,7 +3902,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
@@ -3923,6 +3923,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;
@@ -4654,7 +4658,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;
+ }
}
ZEND_TRY_ASSIGN_LONG(z_width, ImageInfo.Thumbnail.width);
ZEND_TRY_ASSIGN_LONG(z_height, ImageInfo.Thumbnail.height);
diff --git a/ext/exif/tests/bug77540.jpg b/ext/exif/tests/bug77540.jpg
new file mode 100644
index 0000000..559022d
Binary files /dev/null and b/ext/exif/tests/bug77540.jpg differ
diff --git a/ext/exif/tests/bug77540.phpt b/ext/exif/tests/bug77540.phpt
new file mode 100644
index 0000000..a284e1f
--- /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