Skip to content

Commit 5f13c62

Browse files
committed
Fix GH-17198: SplFixedArray assertion failure with get_object_vars
Because the properties table contains both a numeric index and a string index that map to 0 in a symbol table, this causes an assertion failure. Looking at the manual page of get_object_vars(), it seems that only real properties must be included. Given that SplFixedArray's elements are not accessible like properties, they should be excluded. This restores PHP 8.3 behaviour. The reason that this didn't cause problems on 8.3 is because it used a different handler (get_properties). Closes GH-17206.
1 parent e247461 commit 5f13c62

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ PHP NEWS
7575
on SO_SNDTIMEO/SO_RCVTIMEO for socket_set_option().
7676
(David Carlier)
7777

78+
- SPL:
79+
. Fixed bug GH-17198 (SplFixedArray assertion failure with get_object_vars).
80+
(nielsdos)
81+
7882
- Streams:
7983
. Fixed bug GH-17037 (UAF in user filter when adding existing filter name due
8084
to incorrect error handling). (nielsdos)

ext/spl/spl_fixedarray.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ static HashTable* spl_fixedarray_object_get_properties_for(zend_object *obj, zen
239239
zval *const elements = intern->array.elements;
240240
HashTable *ht = zend_new_array(size);
241241

242-
for (zend_long i = 0; i < size; i++) {
243-
Z_TRY_ADDREF_P(&elements[i]);
244-
zend_hash_next_index_insert(ht, &elements[i]);
242+
/* The array elements are not *real properties*. */
243+
if (purpose != ZEND_PROP_PURPOSE_GET_OBJECT_VARS) {
244+
for (zend_long i = 0; i < size; i++) {
245+
Z_TRY_ADDREF_P(&elements[i]);
246+
zend_hash_next_index_insert(ht, &elements[i]);
247+
}
245248
}
249+
246250
if (source_properties && zend_hash_num_elements(source_properties) > 0) {
247251
zend_long nkey;
248252
zend_string *skey;

ext/spl/tests/gh17198.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-17198 (SplFixedArray assertion failure with get_object_vars)
3+
--FILE--
4+
<?php
5+
#[AllowDynamicProperties]
6+
class MySplFixedArray extends SplFixedArray {
7+
}
8+
$array = new MySplFixedArray(2);
9+
$array->{0} = [];
10+
var_dump(get_object_vars($array));
11+
?>
12+
--EXPECT--
13+
array(1) {
14+
[0]=>
15+
array(0) {
16+
}
17+
}

0 commit comments

Comments
 (0)