Skip to content

Fix GH-14124: Segmentation fault on unknown address 0x0001ffff8041 with XML extension under certain memory limit #14126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ext/xml/tests/gh14124.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-14124 (Segmentation fault on unknown address 0x0001ffff8041 with XML extension under certain memory limit)
--EXTENSIONS--
xml
--INI--
memory_limit=33M
--SKIPIF--
<?php
if (!defined("LIBXML_VERSION")) die('skip this is a libxml2 test');
if (getenv('SKIP_ASAN')) die('xleak libxml does not use the request allocator');
?>
--FILE--
<?php
function createParser(bool $huge) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_PARSE_HUGE, $huge);
return $parser;
}

$long_text = str_repeat("A", 1000 * 1000 * 5 /* 5 MB */);
$long_xml_head = "<?xml version=\"1.0\"?><container><$long_text/><$long_text/><second>foo</second>";
$long_xml_tail = "</container>";
$parser = createParser(true);
xml_parse_into_struct($parser, $long_xml_head . $long_xml_tail, $values, $index);
?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
1 change: 1 addition & 0 deletions ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ PHP_FUNCTION(xml_parse_into_struct)
parser->level = 0;
xml_parser_free_ltags(parser);
parser->ltags = safe_emalloc(XML_MAXLEVEL, sizeof(char *), 0);
memset(parser->ltags, 0, XML_MAXLEVEL * sizeof(char *));

XML_SetElementHandler(parser->parser, _xml_startElementHandler, _xml_endElementHandler);
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
Expand Down
Loading