Skip to content

Commit 7f0705b

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
2 parents 8f9626c + 673babe commit 7f0705b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/simplexml/simplexml.c

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

18081808
if (type == _IS_BOOL) {
1809-
node = php_sxe_get_first_node(sxe, NULL);
1809+
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
18101810
if (node) {
18111811
ZVAL_TRUE(writeobj);
18121812
} else {
@@ -1816,7 +1816,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18161816
}
18171817

18181818
if (sxe->iter.type != SXE_ITER_NONE) {
1819-
node = php_sxe_get_first_node(sxe, NULL);
1819+
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
18201820
if (node) {
18211821
contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, node->children, 1);
18221822
}

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)