From 5b00437a09de5bb0ae1631527d519e6ad9851a33 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Thu, 9 Jul 2026 11:39:37 -0700 Subject: [PATCH 1/3] Add regression tests for `ReflectionConstant::__toString()` with null bytes So that when the output is fixed the change can be confirmed in tests --- .../tests/ReflectionConstant_null_byte_value.phpt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ext/reflection/tests/ReflectionConstant_null_byte_value.phpt diff --git a/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt new file mode 100644 index 000000000000..5e1b855eed05 --- /dev/null +++ b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-22658: ReflectionConstant with a string value with a null byte +--FILE-- +getValue() ); + +?> +--EXPECTF-- +Constant [ string DEMO ] { f } +string(4) "f%0oo" From ed3e06a6738b5ab9b7ed8e92cda79832cd172ea1 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Thu, 9 Jul 2026 11:41:30 -0700 Subject: [PATCH 2/3] GH-22658: avoid truncation on null bytes in `ReflectionConstant::__toString()` --- ext/reflection/php_reflection.c | 2 +- ext/reflection/tests/ReflectionConstant_null_byte_value.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e747a642778c..661b1eb1f3a4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -585,7 +585,7 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c if (Z_TYPE_P(value) == IS_ARRAY) { smart_str_append(str, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED)); } else if (Z_TYPE_P(value) == IS_STRING) { - smart_str_appends(str, Z_STRVAL_P(value)); + smart_str_append(str, Z_STR_P(value)); } else { zend_string *tmp_value_str; zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str); diff --git a/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt index 5e1b855eed05..8b6a8e85c2fc 100644 --- a/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt +++ b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt @@ -10,5 +10,5 @@ var_dump( $r->getValue() ); ?> --EXPECTF-- -Constant [ string DEMO ] { f } +Constant [ string DEMO ] { f%0oo } string(4) "f%0oo" From 834bdcedd1c89cdbc722567a6c4f23c3df1d2554 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 10 Jul 2026 07:22:08 -0700 Subject: [PATCH 3/3] NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 2d0abd7eb42f..7324e5c591aa 100644 --- a/NEWS +++ b/NEWS @@ -65,6 +65,8 @@ PHP NEWS ReflectionParameter::__construct()). (jorgsowa) . Fixed bug GH-22441 (ReflectionClass::hasProperty() and getProperty() ignore dynamic properties shadowing a private parent property). (iliaal) + . Fixed bug GH-22658 (ReflectionConstant::__toString() with a string value + with null bytes truncates output). (DanielEScherzer) - Session: . Fixed bug GH-21314 (Different session garbage collector behavior between