[php-src] PHP-8.5: ext/gd: Fix imagecreatefromstring() continuing after the length error

From: Date: Fri, 13 Nov 2026 04:59:16 +0000
Subject: [php-src] PHP-8.5: ext/gd: Fix imagecreatefromstring() continuing after the length error
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143670@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: David Carlier (devnexen) Date: 2026-11-13T04:57:33Z Commit: https://github.com/php/php-src/commit/794fea483fbecd5604c904c8e39c7eae845c505c Raw diff: https://github.com/php/php-src/commit/794fea483fbecd5604c904c8e39c7eae845c505c.diff ext/gd: Fix imagecreatefromstring() continuing after the length error imagecreatefromstring() threw the ValueError for a string longer than INT_MAX but did not return, so it went on decoding the data with the exception pending. Return after throwing. Close GH-25411 Changed paths: A ext/gd/tests/imagecreatefromstring_too_long.phpt M NEWS M ext/gd/gd.c Diff: diff --git a/NEWS b/NEWS index bdafdf2ee9c1..1ccaf0b661e6 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,10 @@ PHP NEWS . Fixed stack overflow in filter_var() and filter_var_array() with deeply nested arrays. (Eyüp Can Akman) +- GD: + . Fixed imagecreatefromstring() continuing to decode after throwing for a + string longer than INT_MAX. (lacatoire) + - MBString: . Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with deeply nested arrays. (Eyüp Can Akman) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 2ac763824436..6f412a339f85 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1451,6 +1451,7 @@ PHP_FUNCTION(imagecreatefromstring) if (ZSTR_LEN(data) > INT_MAX) { zend_argument_value_error(1, "is too long"); + RETURN_THROWS(); } imtype = _php_image_type(data); diff --git a/ext/gd/tests/imagecreatefromstring_too_long.phpt b/ext/gd/tests/imagecreatefromstring_too_long.phpt new file mode 100644 index 000000000000..97ab5c9e495d --- /dev/null +++ b/ext/gd/tests/imagecreatefromstring_too_long.phpt @@ -0,0 +1,24 @@ +--TEST-- +imagecreatefromstring(): a string longer than INT_MAX throws without decoding it +--EXTENSIONS-- +gd +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die('skip 64-bit only'); +if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); +?> +--INI-- +memory_limit=-1 +--FILE-- +<?php +$s = str_repeat("x", 2147483648); +try { + imagecreatefromstring($s); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +echo "Done\n"; +?> +--EXPECT-- +imagecreatefromstring(): Argument #1 ($data) is too long +Done

« previous php.cvs (#143670) next »