[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Fri, 30 Oct 2026 14:49:00 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143012@lists.php.net to get a copy of this message
Author: Arnaud Le Blanc (arnaud-lb) Date: 2026-10-30T15:47:20+01:00 Commit: https://github.com/php/php-src/commit/4bba569f4c591d068c60b6c3388569654b72074d Raw diff: https://github.com/php/php-src/commit/4bba569f4c591d068c60b6c3388569654b72074d.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: Fix potential infinite recursion in HYBRID/TAILCALL VMs (#25039) Changed paths: A Zend/tests/vm_interrupt_rearm.phpt M NEWS M Zend/zend_vm_def.h M Zend/zend_vm_execute.h M ext/zend_test/php_test.h M ext/zend_test/test.c Diff: diff --git a/NEWS b/NEWS index 043842f2138b..e3bd3398dc6b 100644 --- a/NEWS +++ b/NEWS @@ -111,6 +111,8 @@ PHP NEWS after restart. (Pavel Gushcha) . Fix opcache.interned_strings_buffer being 0 in threads started later (ZTS). (Pavel Gushcha) + . Fixed potential infinite recursion/hang (HYBRID/TAILCALL respectively) + when zend_interrupt_function resets EG(vm_interrupt). (Levi Morrison) - OpenSSL: . Fixed build with OpenSSL 4.1. (Weilin Du) diff --git a/Zend/tests/vm_interrupt_rearm.phpt b/Zend/tests/vm_interrupt_rearm.phpt new file mode 100644 index 000000000000..605cb59086d7 --- /dev/null +++ b/Zend/tests/vm_interrupt_rearm.phpt @@ -0,0 +1,26 @@ +--TEST-- +VM interrupt re-armed by the interrupt handler must not stop execution from making progress +--DESCRIPTION-- +zend_test.rearm_vm_interrupt installs a zend_interrupt_function that sets +EG(vm_interrupt) again every time it runs, so an interrupt is always pending. +After handling an interrupt the VM has to run the next opline before it checks +the flag again, otherwise it calls the handler forever (or recurses until the +stack overflows). +--EXTENSIONS-- +zend_test +--INI-- +zend_test.rearm_vm_interrupt=1 +--FILE-- +<?php +function inc(int $x): int { + return $x + 1; +} + +$n = 0; +for ($i = 0; $i < 1000; $i++) { + $n = inc($n); +} +var_dump($n); +?> +--EXPECT-- +int(1000) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c39b82f01608..f456e33948f5 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -10752,7 +10752,11 @@ ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY) } } - ZEND_VM_ENTER(); + /* Like ZEND_VM_ENTER() but don't check for interrupts yet to avoid recursion if the + * interrupt handler re-sets the vm_interrupt flag. */ + execute_data = EG(current_execute_data); + LOAD_OPLINE(); + ZEND_VM_LEAVE(); } ZEND_VM_CONTINUE(); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 89fefc884b0f..0e589cc6b5b0 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -4066,7 +4066,11 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV } } - ZEND_VM_ENTER(); + /* Like ZEND_VM_ENTER() but don't check for interrupts yet to avoid recursion if the + * interrupt handler re-sets the vm_interrupt flag. */ + execute_data = EG(current_execute_data); + LOAD_OPLINE(); + ZEND_VM_LEAVE(); } ZEND_VM_CONTINUE(); } diff --git a/ext/zend_test/php_test.h b/ext/zend_test/php_test.h index 7b5180d1a731..591121b4c02f 100644 --- a/ext/zend_test/php_test.h +++ b/ext/zend_test/php_test.h @@ -52,6 +52,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test) HashTable *global_weakmap; int replace_zend_execute_ex; int register_passes; + bool rearm_vm_interrupt; bool print_stderr_mshutdown; zend_long limit_copy_file_range; int observe_opline_in_zendmm; diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 02f09a5a7ab8..661cba8b8c1e 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -2224,10 +2224,24 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call) zval_ptr_dtor(&rv); } +static void (*zend_test_prev_interrupt_function)(zend_execute_data *execute_data); + +/* The VM clears EG(vm_interrupt) before calling this, so setting it again + * leaves an interrupt pending at all times. The VM must still make progress. */ +static void zend_test_rearm_interrupt_function(zend_execute_data *execute_data) +{ + zend_atomic_bool_store_ex(&EG(vm_interrupt), true); + + if (zend_test_prev_interrupt_function) { + zend_test_prev_interrupt_function(execute_data); + } +} + PHP_INI_BEGIN() PHP_INI_ENTRY("zend_test.register_system_entropy", "0", PHP_INI_SYSTEM, NULL) STD_PHP_INI_BOOLEAN("zend_test.replace_zend_execute_ex", "0", PHP_INI_SYSTEM, OnUpdateBool, replace_zend_execute_ex, zend_zend_test_globals, zend_test_globals) STD_PHP_INI_BOOLEAN("zend_test.register_passes", "0", PHP_INI_SYSTEM, OnUpdateBool, register_passes, zend_zend_test_globals, zend_test_globals) + STD_PHP_INI_BOOLEAN("zend_test.rearm_vm_interrupt", "0", PHP_INI_SYSTEM, OnUpdateBool, rearm_vm_interrupt, zend_zend_test_globals, zend_test_globals) STD_PHP_INI_BOOLEAN("zend_test.print_stderr_mshutdown", "0", PHP_INI_SYSTEM, OnUpdateBool, print_stderr_mshutdown, zend_zend_test_globals, zend_test_globals) #ifdef HAVE_COPY_FILE_RANGE STD_PHP_INI_ENTRY("zend_test.limit_copy_file_range", "-1", PHP_INI_ALL, OnUpdateLong, limit_copy_file_range, zend_zend_test_globals, zend_test_globals) @@ -2450,6 +2464,11 @@ PHP_MINIT_FUNCTION(zend_test) zend_optimizer_register_pass(pass2); } + if (ZT_G(rearm_vm_interrupt)) { + zend_test_prev_interrupt_function = zend_interrupt_function; + zend_interrupt_function = zend_test_rearm_interrupt_function; + } + zend_test_observer_init(INIT_FUNC_ARGS_PASSTHRU); zend_test_mm_custom_handlers_minit(INIT_FUNC_ARGS_PASSTHRU); zend_test_fiber_init(); @@ -2469,6 +2488,11 @@ PHP_MSHUTDOWN_FUNCTION(zend_test) zend_test_observer_shutdown(SHUTDOWN_FUNC_ARGS_PASSTHRU); + if (zend_interrupt_function == zend_test_rearm_interrupt_function) { + zend_interrupt_function = zend_test_prev_interrupt_function; + zend_test_prev_interrupt_function = NULL; + } + if (ZT_G(print_stderr_mshutdown)) { fprintf(stderr, "[zend_test] MSHUTDOWN\n"); } @@ -2482,6 +2506,11 @@ PHP_RINIT_FUNCTION(zend_test) zend_hash_init(ZT_G(global_weakmap), 8, NULL, ZVAL_PTR_DTOR, 0); ZT_G(observer_nesting_depth) = 0; zend_test_mm_custom_handlers_rinit(); + + if (ZT_G(rearm_vm_interrupt)) { + zend_atomic_bool_store_ex(&EG(vm_interrupt), true); + } + return SUCCESS; }

« previous php.cvs (#143012) next »