Skip to content

Commit 268cca0

Browse files
committed
add test
1 parent 34eb69e commit 268cca0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ext/xml/tests/gh14637.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
GH-14637 memory leak under memory limit
3+
--EXTENSIONS--
4+
xml
5+
--INI--
6+
memory_limit=20M
7+
--CREDITS--
8+
YuanchengJiang
9+
--FILE--
10+
<?php
11+
function createParser(bool $huge) {
12+
$parser = xml_parser_create();
13+
xml_parser_set_option($parser, XML_OPTION_PARSE_HUGE, $huge);
14+
xml_set_element_handler($parser, function($parser, $data) {
15+
}, function($parser, $data) {
16+
});
17+
return $parser;
18+
}
19+
// Construct XML that is too large to parse without XML_OPTION_PARSE_HUGE
20+
$long_text = str_repeat("A", 1000 * 1000 * 5 /* 5 MB */);
21+
$long_xml_head = "<?xml version=\"1.0\"?><container><$long_text/><$long_text/><second>foo</second>";
22+
$long_xml_tail = "</container>";
23+
$parser = createParser(false);
24+
$ret = xml_parse($parser, $long_xml_head, true);
25+
echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
26+
$parser = createParser(true);
27+
$ret = xml_parse($parser, $long_xml_head, false);
28+
$parser = createParser(true);
29+
$ret = xml_parse_into_struct($parser, $long_xml_head . $long_xml_tail, $values, $index);
30+
?>
31+
--EXPECTF--
32+
ret = 0 (XML_ERR_NAME_REQUIRED)
33+
34+
Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d

0 commit comments

Comments
 (0)