From 09df01a56bf3d86a1b7ccaf7ee058a699c1fcf6b Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Wed, 19 Aug 2026 02:36:00 +0800 Subject: [PATCH 1/3] ext/gd: Fix incorrect argument numbers in GD affine function errors --- NEWS | 4 ++++ ext/gd/gd.c | 4 ++-- ext/gd/tests/bug67248.phpt | 4 ++-- ext/gd/tests/imageaffinematrixconcat_error.phpt | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 ext/gd/tests/imageaffinematrixconcat_error.phpt diff --git a/NEWS b/NEWS index f65c07cf4a7e..351673b250d7 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS . Fixed a use-after-free when cloning a DOMNameSpaceNode after DOMDocument::xinclude(). (iliaal) +- GD: + . Fixed imageaffinematrixget() and imageaffinematrixconcat() reporting the + wrong argument in error messages. (Weilin Du) + - Intl: . Fixed a double-free when IntlGregorianCalendar construction fails after the ICU constructor adopts the TimeZone. (iliaal) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 311900ba7bb3..c12586522594 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -4210,7 +4210,7 @@ PHP_FUNCTION(imageaffinematrixget) case GD_AFFINE_SCALE: { double x, y; if (Z_TYPE_P(options) != IS_ARRAY) { - zend_argument_type_error(1, "must be of type array when using translate or scale"); + zend_argument_type_error(2, "must be of type array when using translate or scale"); RETURN_THROWS(); } @@ -4291,7 +4291,7 @@ PHP_FUNCTION(imageaffinematrixconcat) } if (zend_hash_num_elements(Z_ARRVAL_P(z_m2)) != 6) { - zend_argument_value_error(1, "must have 6 elements"); + zend_argument_value_error(2, "must have 6 elements"); RETURN_THROWS(); } diff --git a/ext/gd/tests/bug67248.phpt b/ext/gd/tests/bug67248.phpt index a002f71c7fd3..5f00b94fadcd 100644 --- a/ext/gd/tests/bug67248.phpt +++ b/ext/gd/tests/bug67248.phpt @@ -17,8 +17,8 @@ for($i=0;$i<7;$i++) { } ?> --EXPECTF-- -!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale -!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale +!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type array when using translate or scale +!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type array when using translate or scale Warning: Object of class stdClass could not be converted to float in %s on line %d array(6) { diff --git a/ext/gd/tests/imageaffinematrixconcat_error.phpt b/ext/gd/tests/imageaffinematrixconcat_error.phpt new file mode 100644 index 000000000000..5c9773c4e896 --- /dev/null +++ b/ext/gd/tests/imageaffinematrixconcat_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +imageaffinematrixconcat() reports the correct argument for an invalid matrix size +--EXTENSIONS-- +gd +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECT-- +imageaffinematrixconcat(): Argument #2 ($matrix2) must have 6 elements From e0452188259842d901d2f156b58ef5f59ad34763 Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Wed, 19 Aug 2026 02:37:29 +0800 Subject: [PATCH 2/3] better tests --- ext/gd/tests/imageaffinematrixconcat_error.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/gd/tests/imageaffinematrixconcat_error.phpt b/ext/gd/tests/imageaffinematrixconcat_error.phpt index 5c9773c4e896..38a191420902 100644 --- a/ext/gd/tests/imageaffinematrixconcat_error.phpt +++ b/ext/gd/tests/imageaffinematrixconcat_error.phpt @@ -6,9 +6,9 @@ gd getMessage(), "\n"; +} catch (ValueError $exception) { + echo $exception::class, ': ', $exception->getMessage(), "\n"; } ?> --EXPECT-- -imageaffinematrixconcat(): Argument #2 ($matrix2) must have 6 elements +ValueError: imageaffinematrixconcat(): Argument #2 ($matrix2) must have 6 elements From 06febbcc46d197fc94a41982ac6b205867aa955e Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Wed, 19 Aug 2026 04:34:57 +0800 Subject: [PATCH 3/3] Update ext/gd/tests/imageaffinematrixconcat_error.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- ext/gd/tests/imageaffinematrixconcat_error.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/gd/tests/imageaffinematrixconcat_error.phpt b/ext/gd/tests/imageaffinematrixconcat_error.phpt index 38a191420902..91b355547f38 100644 --- a/ext/gd/tests/imageaffinematrixconcat_error.phpt +++ b/ext/gd/tests/imageaffinematrixconcat_error.phpt @@ -6,8 +6,8 @@ gd getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT--