Skip to content

Commit e7b022e

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-15868: Assertion failure in xml_parse_into_struct after exception Fix GH-15868: Assertion failure in xml_parse_into_struct after exception
2 parents 5e7a1cc + 778bfce commit e7b022e

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

ext/xml/tests/gh15868.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
GH-15868 (Assertion failure in xml_parse_into_struct after exception)
3+
--EXTENSIONS--
4+
xml
5+
--FILE--
6+
<?php
7+
$parser = xml_parser_create();
8+
xml_set_element_handler($parser,
9+
function ($parser, $name, $attrs) {
10+
throw new Error('stop 1');
11+
}, function ($parser, $name) {
12+
}
13+
);
14+
try {
15+
xml_parse_into_struct($parser, "<container/>", $values, $tags);
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
$parser = xml_parser_create();
21+
xml_set_element_handler($parser,
22+
function ($parser, $name, $attrs) {
23+
}, function ($parser, $name) {
24+
throw new Error('stop 2');
25+
}
26+
);
27+
try {
28+
xml_parse_into_struct($parser, "<container/>", $values, $tags);
29+
} catch (Error $e) {
30+
echo $e->getMessage(), "\n";
31+
}
32+
33+
$parser = xml_parser_create();
34+
xml_set_character_data_handler($parser, function() {
35+
throw new Error('stop 3');
36+
});
37+
try {
38+
xml_parse_into_struct($parser, "<root><![CDATA[x]]></root>", $values, $tags);
39+
} catch (Error $e) {
40+
echo $e->getMessage(), "\n";
41+
}
42+
?>
43+
--EXPECT--
44+
stop 1
45+
stop 2
46+
stop 3

ext/xml/xml.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void xml_startElementHandler(void *userData, const XML_Char *name, const XML_Cha
626626
zval_ptr_dtor(&args[2]);
627627
}
628628

629-
if (!Z_ISUNDEF(parser->data)) {
629+
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
630630
if (parser->level <= XML_MAXLEVEL) {
631631
zval tag, atr;
632632
int atcnt = 0;
@@ -697,7 +697,7 @@ void xml_endElementHandler(void *userData, const XML_Char *name)
697697
zval_ptr_dtor(&args[1]);
698698
}
699699

700-
if (!Z_ISUNDEF(parser->data)) {
700+
if (!Z_ISUNDEF(parser->data) && !EG(exception)) {
701701
zval tag;
702702

703703
if (parser->lastwasopen) {
@@ -746,7 +746,7 @@ void xml_characterDataHandler(void *userData, const XML_Char *s, int len)
746746
zval_ptr_dtor(&args[1]);
747747
}
748748

749-
if (Z_ISUNDEF(parser->data)) {
749+
if (Z_ISUNDEF(parser->data) || EG(exception)) {
750750
return;
751751
}
752752

0 commit comments

Comments
 (0)