com php-src: Fixed bug #71534 (Type confusion in exif_read_ data() leading to heap overflow in debug m ode): NEWS ext/exif/exif.c
ext/exif/tests/bug71 534.phpt ext/exif/tests/bug71534.tiff
| From: | Kalle Sommer Nielsen | Date: | Sun, 07 Aug 2016 03:35:46 +0000 |
| Subject: | com php-src: Fixed bug #71534 (Type confusion in exif_read_ data() leading to heap overflow in debug m ode): NEWS ext/exif/exif.c ext/exif/tests/bug71 534.phpt ext/exif/tests/bug71534.tiff |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93661@lists.php.net to get a copy of this message | ||
Commit: af56fed73b6a2f07127f48e05aa4837bfc06c42d
Author: Kalle Sommer Nielsen <kalle@php.net> Sun, 7 Aug 2016 05:35:46 +0200
Parents: b0263db457720fca5eba74b054736a35a9f28c3f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=af56fed73b6a2f07127f48e05aa4837bfc06c42d
Log:
Fixed bug #71534 (Type confusion in exif_read_data() leading to heap overflow in debug mode)
Unlike the original patch, this does not return an unknown format in case an unsigned compatible
type cannot be found (cases for SINGLE and DOUBLE removed), as these seems rare cases according to
the inline comments.
Note, the test does not test if PHP is in debug mode, although the report originally states it only
occurs there only.
The fix is based on a patch by hlt99 at blinkenshell dot org
Bugs:
https://bugs.php.net/71534
Changed paths:
M NEWS
M ext/exif/exif.c
A ext/exif/tests/bug71534.phpt
A ext/exif/tests/bug71534.tiff
Diff:
diff --git a/NEWS b/NEWS
index 5a63c37..c978a6a 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ PHP NEWS
Samsung, DJI, Panasonic, Sony, Pentax, Minolta & Sigma/Foveon. (Kalle)
. Fixed bug #72682 (exif_read_data() fails to read all data for some
images). (Kalle)
+ . Fixed bug #71534 (Type confusion in exif_read_data() leading to heap
+ overflow in debug mode). (hlt99 at blinkenshell dot org, Kalle)
. Fixed bug #68547 (Exif Header component value check error).
(sjh21a at gmail dot com, Kalle)
.. Fixed bug #66443 (Corrupt EXIF header: maximum directory nesting level
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index d60a17d..5423504 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -1641,6 +1641,20 @@ static double exif_convert_any_format(void *value, int format, int
motorola_inte
}
/* }}} */
+/* {{{ exif_rewrite_tag_format_to_unsigned
+ * Rewrite format tag so that it specifies an unsigned type for a tag */
+static int exif_rewrite_tag_format_to_unsigned(int format)
+{
+ switch(format) {
+ case TAG_FMT_SBYTE: return TAG_FMT_BYTE;
+ case TAG_FMT_SRATIONAL: return TAG_FMT_URATIONAL;
+ case TAG_FMT_SSHORT: return TAG_FMT_USHORT;
+ case TAG_FMT_SLONG: return TAG_FMT_ULONG;
+ }
+ return format;
+}
+/* }}} */
+
/* {{{ exif_convert_any_to_int
* Evaluate number, be it int, rational, or float from directory. */
static size_t exif_convert_any_to_int(void *value, int format, int motorola_intel)
@@ -3304,18 +3318,18 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry,
cha
switch(tag) {
case TAG_IMAGEWIDTH:
case TAG_COMP_IMAGE_WIDTH:
- ImageInfo->Thumbnail.width = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->Thumbnail.width = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
break;
case TAG_IMAGEHEIGHT:
case TAG_COMP_IMAGE_HEIGHT:
- ImageInfo->Thumbnail.height = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->Thumbnail.height = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
break;
case TAG_STRIP_OFFSETS:
case TAG_JPEG_INTERCHANGE_FORMAT:
/* accept both formats */
- ImageInfo->Thumbnail.offset = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->Thumbnail.offset = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
break;
case TAG_STRIP_BYTE_COUNTS:
@@ -3325,13 +3339,13 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry,
cha
/* motorola is easier to read */
ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_TIFF_MM;
}
- ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
break;
case TAG_JPEG_INTERCHANGE_FORMAT_LEN:
if (ImageInfo->Thumbnail.filetype == IMAGE_FILETYPE_UNKNOWN) {
ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_JPEG;
- ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
}
break;
}
@@ -3403,7 +3417,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry,
cha
break;
case TAG_COMP_IMAGE_WIDTH:
- ImageInfo->ExifImageWidth = exif_convert_any_to_int(value_ptr, format,
ImageInfo->motorola_intel);
+ ImageInfo->ExifImageWidth = exif_convert_any_to_int(value_ptr,
exif_rewrite_tag_format_to_unsigned(format), ImageInfo->motorola_intel);
break;
case TAG_FOCALPLANE_X_RES:
diff --git a/ext/exif/tests/bug71534.phpt b/ext/exif/tests/bug71534.phpt
new file mode 100644
index 0000000..1f5fc9d
--- /dev/null
+++ b/ext/exif/tests/bug71534.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Bug #71534 (Type confusion in exif_read_data() leading to heap overflow in debug mode)
+--SKIPIF--
+<?php if (!extension_loaded('exif')) print 'skip exif extension not
available';?>
+--FILE--
+<?php
+// This is kinda bad, I know! But, this generates about 200+ warnings due to its
+// broken TIFF format
+var_dump(@exif_read_data(__DIR__ . DIRECTORY_SEPARATOR . 'bug71534.tiff') === false);
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/exif/tests/bug71534.tiff b/ext/exif/tests/bug71534.tiff
new file mode 100644
index 0000000..1a224d5
Binary files /dev/null and b/ext/exif/tests/bug71534.tiff differ