File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-14124 (Segmentation fault on unknown address 0x0001ffff8041 with XML extension under certain memory limit)
3
+ --EXTENSIONS--
4
+ xml
5
+ --INI--
6
+ memory_limit=33M
7
+ --SKIPIF--
8
+ <?php
9
+ if (!defined ("LIBXML_VERSION " )) die ('skip this is a libxml2 test ' );
10
+ if (getenv ('SKIP_ASAN ' )) die ('xleak libxml does not use the request allocator ' );
11
+ ?>
12
+ --FILE--
13
+ <?php
14
+ function createParser (bool $ huge ) {
15
+ $ parser = xml_parser_create ();
16
+ xml_parser_set_option ($ parser , XML_OPTION_PARSE_HUGE , $ huge );
17
+ return $ parser ;
18
+ }
19
+
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 (true );
24
+ xml_parse_into_struct ($ parser , $ long_xml_head . $ long_xml_tail , $ values , $ index );
25
+ ?>
26
+ --EXPECTF--
27
+ Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
Original file line number Diff line number Diff line change @@ -1363,6 +1363,7 @@ PHP_FUNCTION(xml_parse_into_struct)
1363
1363
parser -> level = 0 ;
1364
1364
xml_parser_free_ltags (parser );
1365
1365
parser -> ltags = safe_emalloc (XML_MAXLEVEL , sizeof (char * ), 0 );
1366
+ memset (parser -> ltags , 0 , XML_MAXLEVEL * sizeof (char * ));
1366
1367
1367
1368
XML_SetElementHandler (parser -> parser , _xml_startElementHandler , _xml_endElementHandler );
1368
1369
XML_SetCharacterDataHandler (parser -> parser , _xml_characterDataHandler );
You can’t perform that action at this time.
0 commit comments