[php-src] master: Merge branch 'PHP-8.6'

From: Date: Mon, 09 Nov 2026 22:25:10 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143504@lists.php.net to get a copy of this message
Author: Jorg Sowa (jorgsowa) Date: 2026-11-09T23:06:28+01:00 Commit: https://github.com/php/php-src/commit/ac9b9c225d1a50c6e2fae083dc30348d8d153c20 Raw diff: https://github.com/php/php-src/commit/ac9b9c225d1a50c6e2fae083dc30348d8d153c20.diff Merge branch 'PHP-8.6' # Conflicts: # NEWS Changed paths: A Zend/tests/offsets/string_offset_read_warning_frees_string.phpt A ext/opcache/tests/jit/fetch_dim_is_undef_offset_frees_string.phpt M Zend/zend_execute.c M ext/opcache/jit/zend_jit_helpers.c Diff: diff --git a/Zend/tests/offsets/string_offset_read_warning_frees_string.phpt b/Zend/tests/offsets/string_offset_read_warning_frees_string.phpt new file mode 100644 index 000000000000..6914142fff58 --- /dev/null +++ b/Zend/tests/offsets/string_offset_read_warning_frees_string.phpt @@ -0,0 +1,25 @@ +--TEST-- +Reading a leading-numeric string offset when the error handler releases the string +--FILE-- +<?php +set_error_handler(function ($errno, $errstr) { + $GLOBALS['s'] = null; + echo $errstr, "\n"; +}); + +function make(int $n) { + return str_repeat("abc", $n); +} + +function test() { + global $s; + return $s["1x"]; +} + +$s = make(2); +test(); +var_dump($s); +?> +--EXPECT-- +Illegal string offset "1x" +NULL diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 57aa16d6a71c..9e3e64801661 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3116,7 +3116,17 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, c if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, /* allow errors */ true, NULL, &trailing_data)) { if (UNEXPECTED(trailing_data)) { + /* The string may be destroyed while throwing the warning. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { + GC_ADDREF(str); + } zend_error(E_WARNING, "Illegal string offset \"%pS\"", Z_STR_P(dim)); + if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { + zend_string_efree(str); + ZVAL_NULL(result); + return; + } } goto out; } diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 02173043492d..2f801a6623d1 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -1287,7 +1287,16 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); goto out; case IS_UNDEF: + /* The string may be destroyed while throwing the notice */ + if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { + GC_ADDREF(str); + } zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var); + if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { + zend_string_efree(str); + ZVAL_NULL(result); + return; + } ZEND_FALLTHROUGH; case IS_NULL: case IS_FALSE: diff --git a/ext/opcache/tests/jit/fetch_dim_is_undef_offset_frees_string.phpt b/ext/opcache/tests/jit/fetch_dim_is_undef_offset_frees_string.phpt new file mode 100644 index 000000000000..e08f50fbdf06 --- /dev/null +++ b/ext/opcache/tests/jit/fetch_dim_is_undef_offset_frees_string.phpt @@ -0,0 +1,31 @@ +--TEST-- +JIT FETCH_DIM_IS: undefined offset variable when the error handler releases the string +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=function +opcache.file_update_protection=0 +--EXTENSIONS-- +opcache +--FILE-- +<?php +set_error_handler(function ($errno, $errstr) { + $GLOBALS['s'] = null; + echo $errstr, "\n"; +}); + +function make(int $n) { + return str_repeat("abc", $n); +} + +function test() { + global $s; + return $s[$undef] ?? "default"; +} + +$s = make(2); +var_dump(test()); +?> +--EXPECT-- +Undefined variable $undef +string(7) "default"

« previous php.cvs (#143504) next »