Skip to content

Commit 673babe

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
2 parents 4bb27e2 + f4f34b6 commit 673babe

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PHP NEWS
1919
within foreach). (nielsdos)
2020
. Fixed bug GH-12223 (Entity reference produces infinite loop in
2121
var_dump/print_r). (nielsdos)
22+
. Fixed bug GH-12208 (SimpleXML infinite loop when a cast is used inside a
23+
foreach). (nielsdos)
2224

2325
14 Sep 2023, PHP 8.3.0RC2
2426

ext/simplexml/simplexml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18531853
sxe = php_sxe_fetch_object(readobj);
18541854

18551855
if (type == _IS_BOOL) {
1856-
node = php_sxe_get_first_node(sxe, NULL);
1856+
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
18571857
if (node) {
18581858
ZVAL_TRUE(writeobj);
18591859
} else {
@@ -1863,7 +1863,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18631863
}
18641864

18651865
if (sxe->iter.type != SXE_ITER_NONE) {
1866-
node = php_sxe_get_first_node(sxe, NULL);
1866+
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
18671867
if (node) {
18681868
contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, node->children, 1);
18691869
}

ext/simplexml/tests/gh12208.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-12208 (SimpleXML infinite loop when a cast is used inside a foreach)
3+
--EXTENSIONS--
4+
simplexml
5+
--FILE--
6+
<?php
7+
8+
$xml = "<root><a>1</a><a>2</a></root>";
9+
$xml = simplexml_load_string($xml);
10+
11+
$a = $xml->a;
12+
13+
foreach ($a as $test) {
14+
var_dump((string) $a->current());
15+
var_dump((string) $a);
16+
var_dump((bool) $a);
17+
}
18+
19+
?>
20+
--EXPECT--
21+
string(1) "1"
22+
string(1) "1"
23+
bool(true)
24+
string(1) "2"
25+
string(1) "1"
26+
bool(true)

0 commit comments

Comments
 (0)