Coerce numeric string keys from iterators when argument unpacking

Fixes GH-18581
Closes GH-19151
This commit is contained in:
Ilija Tovilo 2025-07-16 23:07:40 +02:00
parent 7efbb2e4e0
commit 23ec35bf4a
No known key found for this signature in database
GPG key ID: 5050C66BFCD1015A
4 changed files with 44 additions and 0 deletions

2
NEWS
View file

@ -5,6 +5,8 @@ PHP NEWS
- Core: - Core:
. Fixed GH-19169 build issue with C++17 and ZEND_STATIC_ASSERT macro. . Fixed GH-19169 build issue with C++17 and ZEND_STATIC_ASSERT macro.
(psumbera) (psumbera)
. Fixed bug GH-18581 (Coerce numeric string keys from iterators when argument
unpacking). (ilutov)
- Hash: - Hash:
. Fix crash on clone failure. (nielsdos) . Fix crash on clone failure. (nielsdos)

32
Zend/tests/gh18581.phpt Normal file
View file

@ -0,0 +1,32 @@
--TEST--
GH-18581: Coerce numeric string keys from iterators when argument unpacking
--FILE--
<?php
function g() {
yield '100' => 'first';
yield '101' => 'second';
yield '102' => 'third';
yield 'named' => 'fourth';
}
function test($x = null, $y = null, ...$z) {
var_dump($x, $y, $z);
var_dump($z[0]);
var_dump($z['named']);
}
test(...g());
?>
--EXPECT--
string(5) "first"
string(6) "second"
array(2) {
[0]=>
string(5) "third"
["named"]=>
string(6) "fourth"
}
string(5) "third"
string(6) "fourth"

View file

@ -5236,6 +5236,11 @@ ZEND_VM_C_LABEL(send_again):
} }
name = Z_STR_P(&key); name = Z_STR_P(&key);
zend_ulong tmp;
if (ZEND_HANDLE_NUMERIC(name, tmp)) {
name = NULL;
}
} }
} }

View file

@ -2355,6 +2355,11 @@ send_again:
} }
name = Z_STR_P(&key); name = Z_STR_P(&key);
zend_ulong tmp;
if (ZEND_HANDLE_NUMERIC(name, tmp)) {
name = NULL;
}
} }
} }