Commit 66c0f525665 for php
commit 66c0f525665ddacbf33f755e2a938e110d650a50
Author: lacatoire <la.catoire@gmail.com>
Date: Wed Nov 11 10:40:36 2026 +0100
ext/gd: report the upper bound of the imagecreate() sizes
imagecreate() and imagecreatetruecolor() reject a width or height of
INT_MAX or more with "must be greater than 0", which is false for
every positive value rejected on the upper side.
Close GH-25386
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 5bcf1184631..68e62d9a1e2 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -693,12 +693,12 @@ PHP_FUNCTION(imagecreatetruecolor)
ZEND_PARSE_PARAMETERS_END();
if (x_size <= 0 || x_size >= INT_MAX) {
- zend_argument_value_error(1, "must be greater than 0");
+ zend_argument_value_error(1, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}
if (y_size <= 0 || y_size >= INT_MAX) {
- zend_argument_value_error(2, "must be greater than 0");
+ zend_argument_value_error(2, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}
@@ -1355,12 +1355,12 @@ PHP_FUNCTION(imagecreate)
ZEND_PARSE_PARAMETERS_END();
if (x_size <= 0 || x_size >= INT_MAX) {
- zend_argument_value_error(1, "must be greater than 0");
+ zend_argument_value_error(1, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}
if (y_size <= 0 || y_size >= INT_MAX) {
- zend_argument_value_error(2, "must be greater than 0");
+ zend_argument_value_error(2, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/gd/tests/imagecreate_error.phpt b/ext/gd/tests/imagecreate_error.phpt
index c6a93854687..1abf16d1984 100644
--- a/ext/gd/tests/imagecreate_error.phpt
+++ b/ext/gd/tests/imagecreate_error.phpt
@@ -17,6 +17,6 @@
);
?>
---EXPECT--
-!! [ValueError] imagecreate(): Argument #1 ($width) must be greater than 0
-!! [ValueError] imagecreate(): Argument #2 ($height) must be greater than 0
+--EXPECTF--
+!! [ValueError] imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
+!! [ValueError] imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
diff --git a/ext/gd/tests/imagecreate_error_oversized.phpt b/ext/gd/tests/imagecreate_error_oversized.phpt
new file mode 100644
index 00000000000..333a6e7c208
--- /dev/null
+++ b/ext/gd/tests/imagecreate_error_oversized.phpt
@@ -0,0 +1,26 @@
+--TEST--
+imagecreate()/imagecreatetruecolor(): oversized dimensions produce a correct error message
+--EXTENSIONS--
+gd
+--FILE--
+<?php
+foreach ([PHP_INT_MAX, 2147483647, 4294967296] as $v) {
+ try { imagecreate($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
+ try { imagecreate(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
+ try { imagecreatetruecolor($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
+ try { imagecreatetruecolor(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
+}
+?>
+--EXPECTF--
+ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
+ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
+ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
+ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
diff --git a/ext/gd/tests/imagecreatetruecolor_error2.phpt b/ext/gd/tests/imagecreatetruecolor_error2.phpt
index 0d299d3c11b..f09d6adbc42 100644
--- a/ext/gd/tests/imagecreatetruecolor_error2.phpt
+++ b/ext/gd/tests/imagecreatetruecolor_error2.phpt
@@ -19,6 +19,6 @@
);
?>
---EXPECT--
-!! [ValueError] imagecreatetruecolor(): Argument #1 ($width) must be greater than 0
-!! [ValueError] imagecreatetruecolor(): Argument #2 ($height) must be greater than 0
+--EXPECTF--
+!! [ValueError] imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
+!! [ValueError] imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d