Skip to content

Fix DOMXPath crash wrapping a foreign node after a nodeset callback - #23253

Open
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/xpath-foreign-doc
Open

Fix DOMXPath crash wrapping a foreign node after a nodeset callback#23253
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/xpath-foreign-doc

Conversation

@iliaal

@iliaal iliaal commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

xpath_callbacks.node_list stores both DOM objects and arrays (nodeset-mode php:function args). dom_xpath_intern_for_doc did Z_DOMOBJ_P on every entry. Same-document results take the early return; a later callback that returns a node from another document walks leftover arrays first. This skips non-objects and recurses into arrays. PHP-8.5 is the lowest branch with intern_for_doc.

dom_xpath_intern_for_doc walked xpath_callbacks.node_list with
Z_DOMOBJ_P on every entry. That list also stores arrays (nodeset-mode
callback arguments). Same-document results take the early return; a
later php:function that returns a node from another document walks
the leftover array first. Skip non-objects and recurse into arrays
so the matching intern is found instead of type-confusing the array.
Comment thread ext/dom/xpath.c
ZEND_HASH_PACKED_FOREACH_VAL(node_list, entry) {
dom_object *obj = Z_DOMOBJ_P(entry);
if (obj->document && obj->document->ptr == doc) {
ZEND_HASH_FOREACH_VAL(node_list, entry) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what s the reason of this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants