Skip to content

Don't use recursion when transferring a DOM internal document pointer #16180

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 1 commit into from
Oct 3, 2024
Merged
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
28 changes: 16 additions & 12 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ PHP_METHOD(DOMDocument, getElementById)
}
/* }}} end dom_document_get_element_by_id */

static zend_always_inline void php_dom_transfer_document_ref_single_node(xmlNodePtr node, php_libxml_ref_obj *new_document)
static void php_dom_transfer_document_ref_single_node(xmlNodePtr node, php_libxml_ref_obj *new_document)
{
php_libxml_node_ptr *iteration_object_ptr = node->_private;
if (iteration_object_ptr) {
Expand All @@ -1087,21 +1087,25 @@ static zend_always_inline void php_dom_transfer_document_ref_single_node(xmlNode
}
}

static void php_dom_transfer_document_ref(xmlNodePtr node, php_libxml_ref_obj *new_document)
static void php_dom_transfer_document_ref_single_aux(xmlNodePtr node, php_libxml_ref_obj *new_document)
{
if (node->children) {
php_dom_transfer_document_ref(node->children, new_document);
php_dom_transfer_document_ref_single_node(node, new_document);
if (node->type == XML_ELEMENT_NODE) {
for (xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next) {
php_dom_transfer_document_ref_single_node((xmlNodePtr) attr, new_document);
}
}
}

while (node) {
if (node->type == XML_ELEMENT_NODE) {
for (xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next) {
php_dom_transfer_document_ref_single_node((xmlNodePtr) attr, new_document);
}
}
static void php_dom_transfer_document_ref(xmlNodePtr node, php_libxml_ref_obj *new_document)
{
xmlNodePtr base = node;
php_dom_transfer_document_ref_single_aux(base, new_document);

php_dom_transfer_document_ref_single_node(node, new_document);
node = node->next;
node = node->children;
while (node != NULL) {
php_dom_transfer_document_ref_single_aux(node, new_document);
node = php_dom_next_in_tree_order(node, base);
}
}

Expand Down