Skip to content

Commit a89aaf6

Browse files
committed
Don't throw from imagecreatefromstring() with too short string
If the string is too short, we should treat this the same way as an unrecognized image type. This function should be usable to determine whether something is a valid image without doing any checks beforehand.
1 parent 7a61984 commit a89aaf6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ext/gd/gd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,9 @@ PHP_FUNCTION(imagecreatefromstring)
14831483
}
14841484

14851485
if (ZSTR_LEN(data) < sizeof(sig)) {
1486-
zend_argument_value_error(1, "cannot be empty");
1487-
RETURN_THROWS();
1486+
/* Handle this the same way as an unknown image type. */
1487+
php_error_docref(NULL, E_WARNING, "Data is not in a recognized format");
1488+
RETURN_FALSE;
14881489
}
14891490

14901491
memcpy(sig, ZSTR_VAL(data), sizeof(sig));

ext/gd/tests/createfromstring.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ $im = imagecreatefromstring(' asdf jklp foo');
6262
--EXPECTF--
6363
createfromstring truecolor png: ok
6464
createfromstring palette png: ok
65-
imagecreatefromstring(): Argument #1 ($data) cannot be empty
6665

67-
Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d
66+
Warning: imagecreatefromstring(): Data is not in a recognized format in %s on line %d
67+
68+
Warning: imagecreatefromstring(): Data is not in a recognized format in %s on line %d

0 commit comments

Comments
 (0)