Skip to content

Commit f9803d4

Browse files
nielsdoscharmitro
authored andcommitted
Fix phpGH-17409: Assertion failure Zend/zend_hash.c:1730
The array merging function may still hold the properties array while the object is already being destroyed. Therefore, we should take into account the refcount in simplexml's destruction code. It may be possible to trigger this in other ways too. Closes phpGH-17421.
1 parent dc80c56 commit f9803d4

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ PHP NEWS
2828
- PHPDBG:
2929
. Fix crashes in function registration + test. (nielsdos, Girgias)
3030

31+
- SimpleXML:
32+
. Fixed bug GH-17409 (Assertion failure Zend/zend_hash.c:1730). (nielsdos)
33+
3134
- SNMP:
3235
. Fixed bug GH-17330 (SNMP::setSecurity segfault on closed session).
3336
(David Carlier)

ext/simplexml/simplexml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,8 +2189,8 @@ static void sxe_object_free_storage(zend_object *object)
21892189
sxe_object_free_iterxpath(sxe);
21902190

21912191
if (sxe->properties) {
2192-
zend_hash_destroy(sxe->properties);
2193-
FREE_HASHTABLE(sxe->properties);
2192+
ZEND_ASSERT(!(GC_FLAGS(sxe->properties) & IS_ARRAY_IMMUTABLE));
2193+
zend_hash_release(sxe->properties);
21942194
}
21952195
}
21962196
/* }}} */

ext/simplexml/tests/gh17409.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-17409 (Assertion failure Zend/zend_hash.c)
3+
--EXTENSIONS--
4+
simplexml
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$root = simplexml_load_string('<?xml version="1.0"?>
10+
<root xmlns:reserved="reserved-ns">
11+
<child reserved:attribute="Sample" />
12+
</root>
13+
');
14+
// Need to use $GLOBALS such that simplexml object is destroyed
15+
var_dump(array_merge_recursive($GLOBALS, $GLOBALS)["root"]);
16+
?>
17+
--EXPECT--
18+
array(1) {
19+
["child"]=>
20+
array(0) {
21+
}
22+
}

0 commit comments

Comments
 (0)