[php-src] PHP-8.4: SCCP: Fix constant propagation when unpacking into partial arrays (#25508)
| From: | Weilin Du via GitHub | Date: | Fri, 20 Nov 2026 11:15:45 +0000 |
| Subject: | [php-src] PHP-8.4: SCCP: Fix constant propagation when unpacking into partial arrays (#25508) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143963@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Committer: GitHub (web-flow)
Pusher: arnaud-lb
Date: 2026-11-20T12:15:42+01:00
Commit: https://github.com/php/php-src/commit/3e87610fe66b4a16533b04df4670a6481eeb101e
Raw diff: https://github.com/php/php-src/commit/3e87610fe66b4a16533b04df4670a6481eeb101e.diff
SCCP: Fix constant propagation when unpacking into partial arrays (#25508)
Changed paths:
A ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
M NEWS
M Zend/Optimizer/sccp.c
Diff:
diff --git a/NEWS b/NEWS
index 84b2777e2587..ed8b3711ebef 100644
--- a/NEWS
+++ b/NEWS
@@ -104,6 +104,8 @@ PHP NEWS
(pavimus)
. Fixed opcache.enable_file_override lookups racing with OPcache restarts
(pavimus)
+ . Fixed incorrect constant propagation when unpacking into partially known
+ arrays. (Weilin Du)
- PDO_Firebird:
. Fixed stack buffer overflow with long connection user names, passwords,
diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c
index ab863fd093d2..b3f633ee226a 100644
--- a/Zend/Optimizer/sccp.c
+++ b/Zend/Optimizer/sccp.c
@@ -540,6 +540,9 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) {
if (key) {
value = zend_hash_update(Z_ARR_P(result), key, value);
+ } else if (IS_PARTIAL_ARRAY(result)) {
+ /* The next free index of a partial array is unknown. */
+ continue;
} else {
value = zend_hash_next_index_insert(Z_ARR_P(result), value);
}
diff --git a/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
b/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
new file mode 100644
index 000000000000..0198ca263ea7
--- /dev/null
+++ b/ext/opcache/tests/opt/sccp_array_unpack_partial.phpt
@@ -0,0 +1,40 @@
+--TEST--
+SCCP must not infer numeric keys when unpacking into a partial array
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.jit=0
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function test($unknown) {
+ $array = [$unknown, ...[42]];
+ var_dump($array[0], $array[1]);
+
+ $array = [10, $unknown, ...[42, 43]];
+ var_dump($array[0], $array[1], $array[2], $array[3]);
+
+ $array = [100 => $unknown, ...[42]];
+ var_dump($array[0] ?? 'missing', $array[100], $array[101]);
+
+ $array = [$unknown, 'key' => 0, ...[42, 'key' => 43], 44];
+ var_dump($array[0], $array[1], $array[2], $array['key']);
+}
+test(7);
+?>
+--EXPECT--
+int(7)
+int(42)
+int(10)
+int(7)
+int(42)
+int(43)
+string(7) "missing"
+int(7)
+int(42)
+int(7)
+int(42)
+int(44)
+int(43)