From e3cac07a9b60fdfa2420db9447ee58634feaab88 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 1 May 2025 00:28:22 +0200 Subject: [PATCH 1/4] Fix numfmt_parse_currency() reference handling Closes GH-18472. --- ext/intl/formatter/formatter_parse.c | 5 ++--- .../numfmt_parse_currency_references.phpt | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 ext/intl/tests/numfmt_parse_currency_references.phpt diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.c index 8ea066c586c..c31ece7dd98 100644 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.c @@ -135,7 +135,7 @@ PHP_FUNCTION( numfmt_parse_currency ) FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz/|z!", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz|z!", &object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE ) { RETURN_THROWS(); @@ -165,8 +165,7 @@ PHP_FUNCTION( numfmt_parse_currency ) /* Convert parsed currency to UTF-8 and pass it back to caller. */ u8str = intl_convert_utf16_to_utf8(currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" ); - zval_ptr_dtor( zcurrency ); - ZVAL_NEW_STR(zcurrency, u8str); + ZEND_TRY_ASSIGN_REF_NEW_STR(zcurrency, u8str); RETVAL_DOUBLE( number ); } diff --git a/ext/intl/tests/numfmt_parse_currency_references.phpt b/ext/intl/tests/numfmt_parse_currency_references.phpt new file mode 100644 index 00000000000..06427a73693 --- /dev/null +++ b/ext/intl/tests/numfmt_parse_currency_references.phpt @@ -0,0 +1,20 @@ +--TEST-- +numfmt_parse_currency() reference handling +--EXTENSIONS-- +intl +--FILE-- +prop); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECT-- +Cannot assign string to reference held by property Test::$prop of type int From e3105f5f1e417bd63b4fb06516ee0b40cd33aa81 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 1 May 2025 00:19:51 +0200 Subject: [PATCH 2/4] Fix reference handling of grapheme_extract() Closes GH-18471. --- ext/intl/grapheme/grapheme_string.c | 17 ++++++----------- .../tests/grapheme_extract_references.phpt | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 ext/intl/tests/grapheme_extract_references.phpt diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index a9cfd3d2ea6..698b75ce30b 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -711,15 +711,10 @@ PHP_FUNCTION(grapheme_extract) } if ( NULL != next ) { - if ( !Z_ISREF_P(next) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "grapheme_extract: 'next' was not passed by reference", 0 ); - RETURN_FALSE; - } else { - ZVAL_DEREF(next); - /* initialize next */ - zval_ptr_dtor(next); - ZVAL_LONG(next, lstart); + ZEND_ASSERT(Z_ISREF_P(next)); + ZEND_TRY_ASSIGN_REF_LONG(next, lstart); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); } } @@ -776,7 +771,7 @@ PHP_FUNCTION(grapheme_extract) if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) { size_t nsize = MIN(size, str_len); if ( NULL != next ) { - ZVAL_LONG(next, start+nsize); + ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize); } RETURN_STRINGL(pstr, nsize); } @@ -810,7 +805,7 @@ PHP_FUNCTION(grapheme_extract) ubrk_close(bi); if ( NULL != next ) { - ZVAL_LONG(next, start+ret_pos); + ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos); } RETURN_STRINGL(((char *)pstr), ret_pos); diff --git a/ext/intl/tests/grapheme_extract_references.phpt b/ext/intl/tests/grapheme_extract_references.phpt new file mode 100644 index 00000000000..33368279a1a --- /dev/null +++ b/ext/intl/tests/grapheme_extract_references.phpt @@ -0,0 +1,19 @@ +--TEST-- +grapheme_extract() references handling +--EXTENSIONS-- +intl +--FILE-- +prop; +grapheme_extract("test", 4, next: $next); +var_dump($test); +?> +--EXPECT-- +object(Test)#1 (1) { + ["prop"]=> + &string(1) "4" +} From a090e59b37d70bca5c114e13db462c44bfbb4140 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:42:53 +0200 Subject: [PATCH 3/4] Fix reference handling of IntlTimeZone::getCanonicalID/intltz_get_canonical_id Closes GH-18469. --- .../tests/intltz_get_canonical_id_refs.phpt | 19 +++++++++++++++++++ ext/intl/timezone/timezone_methods.cpp | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 ext/intl/tests/intltz_get_canonical_id_refs.phpt diff --git a/ext/intl/tests/intltz_get_canonical_id_refs.phpt b/ext/intl/tests/intltz_get_canonical_id_refs.phpt new file mode 100644 index 00000000000..973b7006c7d --- /dev/null +++ b/ext/intl/tests/intltz_get_canonical_id_refs.phpt @@ -0,0 +1,19 @@ +--TEST-- +IntlTimeZone::getCanonicalID: refs test +--EXTENSIONS-- +intl +--FILE-- +prop; +print_R(intltz_get_canonical_id('Portugal', $ref)); +var_dump($test); +?> +--EXPECT-- +Europe/Lisbonobject(Test)#1 (1) { + ["prop"]=> + &string(1) "1" +} diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp index 580a721e79e..d360ab3a688 100644 --- a/ext/intl/timezone/timezone_methods.cpp +++ b/ext/intl/timezone/timezone_methods.cpp @@ -291,9 +291,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id) RETVAL_NEW_STR(u8str); if (is_systemid) { /* by-ref argument passed */ - ZVAL_DEREF(is_systemid); - zval_ptr_dtor(is_systemid); - ZVAL_BOOL(is_systemid, isSystemID); + ZEND_TRY_ASSIGN_REF_BOOL(is_systemid, isSystemID); } } From 9c555f5a848810074b7d7266eef430c1b55a5589 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 1 May 2025 10:41:57 +0200 Subject: [PATCH 4/4] Update NEWS for the intl reference fixes --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a2c4da767ec..37f2f7f0819 100644 --- a/NEWS +++ b/NEWS @@ -8,7 +8,7 @@ PHP NEWS correct) (JiriJozif). - Intl: - . datefmt_parse/datefmt_localtime references type system fixes. (nielsdos) + . Fix various reference issues. (nielsdos) - Opcache: . Fixed bug GH-18417 (Windows SHM reattachment fails when increasing