File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,26 @@ PHP_LIBXML_API void php_libxml_node_free_list(xmlNodePtr node)
342
342
if (ptr -> _private ) {
343
343
const php_libxml_node_object * obj = ptr -> _private ;
344
344
if (!obj -> document || obj -> document -> class_type < PHP_LIBXML_CLASS_MODERN ) {
345
- xmlReconciliateNs (curnode -> doc , curnode );
345
+ if (LIBXML_VERSION < 21300 && UNEXPECTED (curnode -> doc == NULL )) {
346
+ /* xmlReconciliateNs() in these versions just uses the document for xmlNewReconciledNs(),
347
+ * which can create an oldNs xml namespace declaration via xmlSearchNs() -> xmlTreeEnsureXMLDecl(). */
348
+ xmlDoc dummy ;
349
+ memset (& dummy , 0 , sizeof (dummy ));
350
+ dummy .type = XML_DOCUMENT_NODE ;
351
+ curnode -> doc = & dummy ;
352
+ xmlReconciliateNs (curnode -> doc , curnode );
353
+ curnode -> doc = NULL ;
354
+
355
+ /* Append oldNs to current node's nsDef, which can be at most one node. */
356
+ if (dummy .oldNs ) {
357
+ ZEND_ASSERT (dummy .oldNs -> next == NULL );
358
+ xmlNsPtr old = curnode -> nsDef ;
359
+ curnode -> nsDef = dummy .oldNs ;
360
+ dummy .oldNs -> next = old ;
361
+ }
362
+ } else {
363
+ xmlReconciliateNs (curnode -> doc , curnode );
364
+ }
346
365
}
347
366
}
348
367
}
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-19098 (libxml<2.13 segmentation fault caused by php_libxml_node_free)
3
+ --EXTENSIONS--
4
+ xmlreader
5
+ dom
6
+ --FILE--
7
+ <?php
8
+
9
+ $ xml_reader = \XMLReader::XML ('
10
+ <sparql xmlns="http://www.w3.org/2005/sparql-results#">
11
+ <results>
12
+ <result><binding xml:id="foo" xmlns:custom="urn:custom" custom:foo="bar" name="s"><uri/></binding></result>
13
+ </results>
14
+ </sparql> ' );
15
+
16
+ $ success = $ xml_reader ->next ("sparql " );
17
+
18
+ $ success = $ xml_reader ->read ();
19
+ $ success = $ xml_reader ->next ("results " );
20
+
21
+ while ($ xml_reader ->read ()) {
22
+ if ($ xml_reader ->next ("result " )) {
23
+ $ result_as_dom_node = $ xml_reader ->expand ();
24
+ $ child = $ result_as_dom_node ->firstChild ;
25
+ unset($ result_as_dom_node );
26
+ var_dump ($ child ->namespaceURI );
27
+ foreach ($ child ->attributes as $ attr ) {
28
+ var_dump ($ attr ->namespaceURI );
29
+ }
30
+ $ doc = new DOMDocument ;
31
+ $ doc ->adoptNode ($ child );
32
+ echo $ doc ->saveXML ($ child ), "\n" ;
33
+ unset($ child );
34
+ break ;
35
+ }
36
+ }
37
+
38
+ ?>
39
+ --EXPECT--
40
+ string(38) "http://www.w3.org/2005/sparql-results#"
41
+ string(36) "http://www.w3.org/XML/1998/namespace"
42
+ string(10) "urn:custom"
43
+ NULL
44
+ <default:binding xmlns:custom="urn:custom" xmlns:default="http://www.w3.org/2005/sparql-results#" xml:id="foo" custom:foo="bar" name="s"><default:uri/></default:binding>
You can’t perform that action at this time.
0 commit comments