@@ -1586,47 +1586,6 @@ PHP_METHOD(DOMDocument, saveXML)
1586
1586
}
1587
1587
/* }}} end dom_document_savexml */
1588
1588
1589
- static xmlNodePtr php_dom_free_xinclude_node (xmlNodePtr cur ) /* {{{ */
1590
- {
1591
- xmlNodePtr xincnode ;
1592
-
1593
- xincnode = cur ;
1594
- cur = cur -> next ;
1595
- xmlUnlinkNode (xincnode );
1596
- php_libxml_node_free_resource (xincnode );
1597
-
1598
- return cur ;
1599
- }
1600
- /* }}} */
1601
-
1602
- static void php_dom_remove_xinclude_nodes (xmlNodePtr cur ) /* {{{ */
1603
- {
1604
- while (cur ) {
1605
- if (cur -> type == XML_XINCLUDE_START ) {
1606
- cur = php_dom_free_xinclude_node (cur );
1607
-
1608
- /* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
1609
- while (cur && cur -> type != XML_XINCLUDE_END ) {
1610
- /* remove xinclude processing nodes from recursive xincludes */
1611
- if (cur -> type == XML_ELEMENT_NODE ) {
1612
- php_dom_remove_xinclude_nodes (cur -> children );
1613
- }
1614
- cur = cur -> next ;
1615
- }
1616
-
1617
- if (cur && cur -> type == XML_XINCLUDE_END ) {
1618
- cur = php_dom_free_xinclude_node (cur );
1619
- }
1620
- } else {
1621
- if (cur -> type == XML_ELEMENT_NODE ) {
1622
- php_dom_remove_xinclude_nodes (cur -> children );
1623
- }
1624
- cur = cur -> next ;
1625
- }
1626
- }
1627
- }
1628
- /* }}} */
1629
-
1630
1589
/* Backported from master branch xml_common.h */
1631
1590
static zend_always_inline xmlNodePtr php_dom_next_in_tree_order (const xmlNode * nodep , const xmlNode * basep )
1632
1591
{
@@ -1660,17 +1619,19 @@ static void dom_xinclude_strip_references(xmlNodePtr basep)
1660
1619
}
1661
1620
}
1662
1621
1663
- /* See GH-14702.
1664
- * We have to remove userland references to xinclude fallback nodes because libxml2 will make clones of these
1622
+ /* See GH-14702 and GH-17847 .
1623
+ * We have to remove userland references to xinclude nodes because libxml2 will make clones of these
1665
1624
* and remove the original nodes. If the originals are removed while there are still userland references
1666
1625
* this will cause memory corruption. */
1667
1626
static void dom_xinclude_strip_fallback_references (const xmlNode * basep )
1668
1627
{
1669
1628
xmlNodePtr current = basep -> children ;
1670
1629
1630
+ /* TODO: try to improve loop search performance */
1671
1631
while (current ) {
1672
- if (current -> type == XML_ELEMENT_NODE && current -> ns != NULL && current -> _private != NULL
1673
- && xmlStrEqual (current -> name , XINCLUDE_FALLBACK )
1632
+ if (current -> type == XML_ELEMENT_NODE
1633
+ && current -> ns != NULL
1634
+ && xmlStrEqual (current -> name , XINCLUDE_NODE )
1674
1635
&& (xmlStrEqual (current -> ns -> href , XINCLUDE_NS ) || xmlStrEqual (current -> ns -> href , XINCLUDE_OLD_NS ))) {
1675
1636
dom_xinclude_strip_references (current );
1676
1637
}
@@ -1684,7 +1645,6 @@ PHP_METHOD(DOMDocument, xinclude)
1684
1645
{
1685
1646
zval * id ;
1686
1647
xmlDoc * docp ;
1687
- xmlNodePtr root ;
1688
1648
zend_long flags = 0 ;
1689
1649
int err ;
1690
1650
dom_object * intern ;
@@ -1703,22 +1663,11 @@ PHP_METHOD(DOMDocument, xinclude)
1703
1663
1704
1664
dom_xinclude_strip_fallback_references ((const xmlNode * ) docp );
1705
1665
1666
+ flags |= XML_PARSE_NOXINCNODE ;
1706
1667
PHP_LIBXML_SANITIZE_GLOBALS (xinclude );
1707
1668
err = xmlXIncludeProcessFlags (docp , (int )flags );
1708
1669
PHP_LIBXML_RESTORE_GLOBALS (xinclude );
1709
1670
1710
- /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
1711
- are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
1712
- but are not wanted in resulting document - must be done even if err as it could fail after
1713
- having processed some xincludes */
1714
- root = (xmlNodePtr ) docp -> children ;
1715
- while (root && root -> type != XML_ELEMENT_NODE && root -> type != XML_XINCLUDE_START ) {
1716
- root = root -> next ;
1717
- }
1718
- if (root ) {
1719
- php_dom_remove_xinclude_nodes (root );
1720
- }
1721
-
1722
1671
php_libxml_invalidate_node_list_cache (intern -> document );
1723
1672
1724
1673
if (err ) {
0 commit comments