Skip to content

Commit 1ea329d

Browse files
peter279knikic
authored andcommitted
Fix bug #77204
Include opened path in getimagesize() error message
1 parent a653240 commit 1ea329d

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ PHP NEWS
5353
- sodium:
5454
. Fixed bug #77646 (sign_detached() strings not terminated). (Frank)
5555

56+
- Standard:
57+
. Fixed bug #77204 (getimagesize(): Read error! should mention file path).
58+
(peter279k)
59+
5660
- tidy:
5761
. Removed the unused $use_include_path parameter from tidy_repair_string().
5862
(cmb)

ext/exif/exif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4673,7 +4673,7 @@ PHP_FUNCTION(exif_imagetype)
46734673
RETURN_FALSE;
46744674
}
46754675

4676-
itype = php_getimagetype(stream, NULL);
4676+
itype = php_getimagetype(stream, imagefile, NULL);
46774677

46784678
php_stream_close(stream);
46794679

ext/standard/image.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,14 +1296,14 @@ PHP_FUNCTION(image_type_to_extension)
12961296

12971297
/* {{{ php_imagetype
12981298
detect filetype from first bytes */
1299-
PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
1299+
PHPAPI int php_getimagetype(php_stream * stream, char *input, char *filetype)
13001300
{
13011301
char tmp[12];
13021302
int twelve_bytes_read;
13031303

13041304
if ( !filetype) filetype = tmp;
13051305
if((php_stream_read(stream, filetype, 3)) != 3) {
1306-
php_error_docref(NULL, E_NOTICE, "Read error!");
1306+
php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input);
13071307
return IMAGE_FILETYPE_UNKNOWN;
13081308
}
13091309

@@ -1314,7 +1314,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
13141314
return IMAGE_FILETYPE_JPEG;
13151315
} else if (!memcmp(filetype, php_sig_png, 3)) {
13161316
if (php_stream_read(stream, filetype+3, 5) != 5) {
1317-
php_error_docref(NULL, E_NOTICE, "Read error!");
1317+
php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input);
13181318
return IMAGE_FILETYPE_UNKNOWN;
13191319
}
13201320
if (!memcmp(filetype, php_sig_png, 8)) {
@@ -1335,7 +1335,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
13351335
return IMAGE_FILETYPE_JPC;
13361336
} else if (!memcmp(filetype, php_sig_riff, 3)) {
13371337
if (php_stream_read(stream, filetype+3, 9) != 9) {
1338-
php_error_docref(NULL, E_NOTICE, "Read error!");
1338+
php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input);
13391339
return IMAGE_FILETYPE_UNKNOWN;
13401340
}
13411341
if (!memcmp(filetype+8, php_sig_webp, 4)) {
@@ -1346,7 +1346,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
13461346
}
13471347

13481348
if (php_stream_read(stream, filetype+3, 1) != 1) {
1349-
php_error_docref(NULL, E_NOTICE, "Read error!");
1349+
php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input);
13501350
return IMAGE_FILETYPE_UNKNOWN;
13511351
}
13521352
/* BYTES READ: 4 */
@@ -1373,7 +1373,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
13731373
return IMAGE_FILETYPE_WBMP;
13741374
}
13751375
if (!twelve_bytes_read) {
1376-
php_error_docref(NULL, E_NOTICE, "Read error!");
1376+
php_error_docref(NULL, E_NOTICE, "Error reading from %s!", input);
13771377
return IMAGE_FILETYPE_UNKNOWN;
13781378
}
13791379
if (php_get_xbm(stream, NULL)) {
@@ -1383,7 +1383,7 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype)
13831383
}
13841384
/* }}} */
13851385

1386-
static void php_getimagesize_from_stream(php_stream *stream, zval *info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
1386+
static void php_getimagesize_from_stream(php_stream *stream, char *input, zval *info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
13871387
{
13881388
int itype = 0;
13891389
struct gfxinfo *result = NULL;
@@ -1392,7 +1392,7 @@ static void php_getimagesize_from_stream(php_stream *stream, zval *info, INTERNA
13921392
RETURN_FALSE;
13931393
}
13941394

1395-
itype = php_getimagetype(stream, NULL);
1395+
itype = php_getimagetype(stream, input, NULL);
13961396
switch( itype) {
13971397
case IMAGE_FILETYPE_GIF:
13981398
result = php_handle_gif(stream);
@@ -1511,7 +1511,7 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) {
15111511
RETURN_FALSE;
15121512
}
15131513

1514-
php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);
1514+
php_getimagesize_from_stream(stream, input, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);
15151515
php_stream_close(stream);
15161516
}
15171517
/* }}} */

ext/standard/php_image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef enum
5656

5757
PHP_MINIT_FUNCTION(imagetypes);
5858

59-
PHPAPI int php_getimagetype(php_stream *stream, char *filetype);
59+
PHPAPI int php_getimagetype(php_stream *stream, char *input, char *filetype);
6060

6161
PHPAPI char * php_image_type_to_mime_type(int image_type);
6262

ext/standard/tests/image/getimagesize_variation3.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ array(0) {
6060

6161
-- Empty File (blank_file.bmp) --
6262

63-
Notice: getimagesize(): Read error! in %s on line %d
63+
Notice: getimagesize(): Error reading from %s! in %s on line %d
6464
bool(false)
6565

66-
Notice: getimagesize(): Read error! in %s on line %d
66+
Notice: getimagesize(): Error reading from %s! in %s on line %d
6767
bool(false)
6868
array(0) {
6969
}

0 commit comments

Comments
 (0)