From 707d483ec33b283c7e86103508b77310989c70cf Mon Sep 17 00:00:00 2001 From: peter279k Date: Wed, 8 May 2019 01:11:19 +0800 Subject: [PATCH] Fix bug for 77204 --- ext/exif/exif.c | 2 +- ext/standard/image.c | 18 +++++++++--------- ext/standard/php_image.h | 2 +- .../tests/image/getimagesize_variation3.phpt | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/exif/exif.c b/ext/exif/exif.c index 2d0695fd1790b..906a1b80c2769 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -4660,7 +4660,7 @@ PHP_FUNCTION(exif_imagetype) RETURN_FALSE; } - itype = php_getimagetype(stream, NULL); + itype = php_getimagetype(stream, imagefile, NULL); php_stream_close(stream); diff --git a/ext/standard/image.c b/ext/standard/image.c index 53c42a0e51066..0f5f4afffaeae 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1298,14 +1298,14 @@ PHP_FUNCTION(image_type_to_extension) /* {{{ php_imagetype detect filetype from first bytes */ -PHPAPI int php_getimagetype(php_stream * stream, char *filetype) +PHPAPI int php_getimagetype(php_stream * stream, char *input, char *filetype) { char tmp[12]; int twelve_bytes_read; if ( !filetype) filetype = tmp; if((php_stream_read(stream, filetype, 3)) != 3) { - php_error_docref(NULL, E_NOTICE, "Read error!"); + php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input); return IMAGE_FILETYPE_UNKNOWN; } @@ -1316,7 +1316,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype) return IMAGE_FILETYPE_JPEG; } else if (!memcmp(filetype, php_sig_png, 3)) { if (php_stream_read(stream, filetype+3, 5) != 5) { - php_error_docref(NULL, E_NOTICE, "Read error!"); + php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input); return IMAGE_FILETYPE_UNKNOWN; } if (!memcmp(filetype, php_sig_png, 8)) { @@ -1337,7 +1337,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype) return IMAGE_FILETYPE_JPC; } else if (!memcmp(filetype, php_sig_riff, 3)) { if (php_stream_read(stream, filetype+3, 9) != 9) { - php_error_docref(NULL, E_NOTICE, "Read error!"); + php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input); return IMAGE_FILETYPE_UNKNOWN; } if (!memcmp(filetype+8, php_sig_webp, 4)) { @@ -1348,7 +1348,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype) } if (php_stream_read(stream, filetype+3, 1) != 1) { - php_error_docref(NULL, E_NOTICE, "Read error!"); + php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input); return IMAGE_FILETYPE_UNKNOWN; } /* BYTES READ: 4 */ @@ -1375,7 +1375,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype) return IMAGE_FILETYPE_WBMP; } if (!twelve_bytes_read) { - php_error_docref(NULL, E_NOTICE, "Read error!"); + php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input); return IMAGE_FILETYPE_UNKNOWN; } if (php_get_xbm(stream, NULL)) { @@ -1385,7 +1385,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype) } /* }}} */ -static void php_getimagesize_from_stream(php_stream *stream, zval *info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ +static void php_getimagesize_from_stream(php_stream *stream, char *input, zval *info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ { int itype = 0; struct gfxinfo *result = NULL; @@ -1394,7 +1394,7 @@ static void php_getimagesize_from_stream(php_stream *stream, zval *info, INTERNA RETURN_FALSE; } - itype = php_getimagetype(stream, NULL); + itype = php_getimagetype(stream, input, NULL); switch( itype) { case IMAGE_FILETYPE_GIF: result = php_handle_gif(stream); @@ -1513,7 +1513,7 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { RETURN_FALSE; } - php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU); + php_getimagesize_from_stream(stream, input, info, INTERNAL_FUNCTION_PARAM_PASSTHRU); php_stream_close(stream); } /* }}} */ diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h index 5f9b07ddeab97..76fec36a92b7d 100644 --- a/ext/standard/php_image.h +++ b/ext/standard/php_image.h @@ -58,7 +58,7 @@ typedef enum PHP_MINIT_FUNCTION(imagetypes); -PHPAPI int php_getimagetype(php_stream *stream, char *filetype); +PHPAPI int php_getimagetype(php_stream *stream, char *input, char *filetype); PHPAPI char * php_image_type_to_mime_type(int image_type); diff --git a/ext/standard/tests/image/getimagesize_variation3.phpt b/ext/standard/tests/image/getimagesize_variation3.phpt index a608047707d12..fba79ed461e67 100644 --- a/ext/standard/tests/image/getimagesize_variation3.phpt +++ b/ext/standard/tests/image/getimagesize_variation3.phpt @@ -60,10 +60,10 @@ array(0) { -- Empty File (blank_file.bmp) -- -Notice: getimagesize(): Read error! in %s on line %d +Notice: getimagesize(): Error reading from %s! in %s on line %d bool(false) -Notice: getimagesize(): Read error! in %s on line %d +Notice: getimagesize(): Error reading from %s! in %s on line %d bool(false) array(0) { }