Commit 36d8455b0ac for php
commit 36d8455b0acd04f3f1fe1c71e60befa6d92f5e78
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date: Sun Nov 8 16:05:35 2026 +0100
Fix GH-25313: Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws
The warning didn't have an exception check after it.
I placed the exception check immediately after the warning so that the
happy-flow isn't affected, this required some restructuring of the code
as well.
Closes GH-25319.
diff --git a/NEWS b/NEWS
index 3ab26f0768f..de80e308a4d 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,8 @@ PHP NEWS
. Fixed stack limit fallback on FreeBSD threads other than the main one.
(Ostap Brehin)
. Fixed propagation of public(set) of readonly trait property. (ilutov)
+ . Fixed bug GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking
+ a generator into a by-ref parameter throws). (ndossche)
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/tests/arg_unpack/gh25313.phpt b/Zend/tests/arg_unpack/gh25313.phpt
new file mode 100644
index 00000000000..072a4f2aa71
--- /dev/null
+++ b/Zend/tests/arg_unpack/gh25313.phpt
@@ -0,0 +1,30 @@
+--TEST--
+GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws)
+--CREDITS--
+YuanchengJiang
+--FILE--
+<?php
+set_error_handler(function($n, $s) { throw new Exception($s); });
+
+function test($a, $b, $c, &$ref) {}
+
+function gen($array) {
+ foreach ($array as $e)
+ yield $e;
+}
+
+try {
+ test(...gen([1, 2]), ...gen([3, 4]));
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+
+try {
+ test(...gen(['a' => 1, 'b' => 2]), ...gen(['c' => 3, 'ref' => 4]));
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+?>
+--EXPECT--
+Exception: Cannot pass by-reference argument 4 of test() by unpacking a Traversable, passing by-value instead
+Exception: Cannot pass by-reference argument 4 of test() by unpacking a Traversable, passing by-value instead
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index f9432cb6585..4d5301ad023 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -5356,6 +5356,7 @@ ZEND_VM_C_LABEL(send_again):
Z_TRY_ADDREF_P(arg);
if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, arg_num)) {
+ ZVAL_NEW_REF(top, arg);
zend_error(
E_WARNING, "Cannot pass by-reference argument %d of %s%s%s()"
" by unpacking a Traversable, passing by-value instead", arg_num,
@@ -5363,7 +5364,10 @@ ZEND_VM_C_LABEL(send_again):
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name)
);
- ZVAL_NEW_REF(top, arg);
+ if (UNEXPECTED(EG(exception) != NULL)) {
+ zend_string_release(name);
+ break;
+ }
} else {
ZVAL_COPY_VALUE(top, arg);
}
@@ -5380,8 +5384,10 @@ ZEND_VM_C_LABEL(send_again):
top = ZEND_CALL_ARG(EX(call), arg_num);
ZVAL_DEREF(arg);
Z_TRY_ADDREF_P(arg);
+ ZEND_CALL_NUM_ARGS(EX(call))++;
if (ARG_MUST_BE_SENT_BY_REF(EX(call)->func, arg_num)) {
+ ZVAL_NEW_REF(top, arg);
zend_error(
E_WARNING, "Cannot pass by-reference argument %d of %s%s%s()"
" by unpacking a Traversable, passing by-value instead", arg_num,
@@ -5389,12 +5395,12 @@ ZEND_VM_C_LABEL(send_again):
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name)
);
- ZVAL_NEW_REF(top, arg);
+ if (UNEXPECTED(EG(exception) != NULL)) {
+ break;
+ }
} else {
ZVAL_COPY_VALUE(top, arg);
}
-
- ZEND_CALL_NUM_ARGS(EX(call))++;
}
funcs->move_forward(iter);
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 3137c55eac0..812402c7931 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ