315 Commits
Author SHA1 Message Date
David Carlier 073853ef33 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-23365: DOMNode::insertBefore() drops the node used as its own reference
2026-09-15 21:26:54 +01:00
David Carlier 0540c2d1ae Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-23365: DOMNode::insertBefore() drops the node used as its own reference
2026-09-15 21:26:47 +01:00
David Carlier a7bdb8b53d Fix GH-23365: DOMNode::insertBefore() drops the node used as its own reference
insertBefore($n, $n) unlinked the node, then rebuilt its position from the
pointers the unlink had just cleared, leaving it out of the document with a
self-referencing sibling list, freed twice at teardown. Retarget the reference
to the node's next sibling, as the modern DOM already does.

Close GH-23379
2026-09-15 21:26:40 +01:00
David Carlier e5623ea1e9 ext/dom: use-after-free via DOMNameSpaceNode after DOMDocument::xinclude().
Fix GH-22624

Close GH-22627
2026-08-16 15:30:23 +01:00
Weilin Du c742440fef Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (#23140)
2026-08-09 00:14:34 +08:00
Weilin Du 19eda22e90 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (#23140)
2026-08-09 00:14:16 +08:00
Weilin Du c4c356a7ba Fix GH-23120: DOMNode::isEqualNode stack overflow on deeply nested trees (#23140) 2026-08-09 00:04:06 +08:00
David Carlier 5ccb145042 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/dom: fix UAF when setting an attribute colliding by local name.
2026-07-22 06:50:48 +01:00
David Carlier 6e7491400a Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/dom: fix UAF when setting an attribute colliding by local name.
2026-07-22 06:50:39 +01:00
David Carlier 3221a076f2 ext/dom: fix UAF when setting an attribute colliding by local name.
Fix #22447

xmlHasProp() matches an attribute by local name only, ignoring its
namespace, whereas xmlAddChild()/xmlAddPrevSibling() dedup an incoming
no-namespace attribute via xmlHasNsProp(..., NULL), which matches only
attributes with no namespace. When both a no-namespace and a namespaced
attribute share a local name, the pre-insertion check unlinked the wrong
(namespaced) attribute, leaving libxml to free the still-wrapped
no-namespace duplicate and producing a use-after-free at request
shutdown.

Use xmlHasNsProp(..., NULL) so the pre-insertion check matches libxml's
internal duplicate detection, as advised by @nwellnhof.

Close GH-22452
2026-07-22 06:50:12 +01:00
David Carlier 8c63ec400c Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/dom: resolve in-scope prefixed QName values during document validation.
2026-06-12 21:38:10 +01:00
David Carlier bb20b5ffb5 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/dom: resolve in-scope prefixed QName values during document validation.
2026-06-12 21:37:57 +01:00
David Carlier 3b5eeb92df ext/dom: resolve in-scope prefixed QName values during document validation.
Fix #22219

Modern DOM keeps namespace declarations off the tree (node->nsDef is NULL),
so libxml's native validators cannot resolve a prefixed QName appearing in
element or attribute content. Temporarily materialize them as nsDef entries
around schema, RelaxNG and DTD validation, reusing the C14N relink
machinery, then restore the tree.

close GH-22224
2026-06-12 21:36:21 +01:00
David Carlier ee3addff5e Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21544: Dom\XMLDocument::C14N() drops namespace declarations on DOM-built documents.
2026-04-22 08:26:00 +01:00
David Carlier 86a1b362f8 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21544: Dom\XMLDocument::C14N() drops namespace declarations on DOM-built documents.
2026-04-22 08:25:49 +01:00
David Carlier d43c523c48 Fix GH-21544: Dom\XMLDocument::C14N() drops namespace declarations on DOM-built documents.
For programmatically built documents (e.g. createElementNS), namespaces
live on node->ns without corresponding xmlns attributes. Create temporary
synthetic nsDef entries so C14N can find them, complementing the existing
xmlns attribute to nsDef conversion.

close GH-21561
2026-04-22 08:25:19 +01:00
Ben Ramsey cf23c1e80e license-update: ext/dom source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
David Carlier 715645f5d7 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21688: SEGV in C14N on empty HTMLDocument.
2026-04-09 21:53:57 +01:00
David Carlier 91842e03a8 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21688: SEGV in C14N on empty HTMLDocument.
2026-04-09 21:53:47 +01:00
David Carlier 19f73c5712 Fix GH-21688: SEGV in C14N on empty HTMLDocument.
close GH-21693
2026-04-09 21:53:28 +01:00
Tim Düsterhus 04f06e8cf2 zend_portability: Remove EMPTY_SWITCH_DEFAULT_CASE() (#20063)
There are several issues with this macro:

- It is incorrectly named: It's not an empty default case. It's an unreachable
  default case.
- It is hiding control flow in its definition, which can be confusing for
  humans and tools (such as Coccinelle) alike, because it looks like it would
  be a statement that belongs to the "current" case rather than opening a new
  one.

Since this macro is exactly as long as explicitly spelling out its definition
(excluding the useless `break;`), it is not even making the code any more
succinct.
2026-04-06 14:46:15 +02:00
David Carlier d5f4c4351a Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21548: Dom\XMLDocument::C14N() emits duplicate xmlns declarations after setAttributeNS().
2026-03-31 22:28:00 +01:00
David Carlier 49dbac9a11 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21548: Dom\XMLDocument::C14N() emits duplicate xmlns declarations after setAttributeNS().
2026-03-31 22:27:24 +01:00
David Carlier 4ee275fd59 Fix GH-21548: Dom\XMLDocument::C14N() emits duplicate xmlns declarations after setAttributeNS().
The xmlns attribute unlinking code in dom_relink_ns_decls_element was
clobbering attr->prev instead of updating the predecessor's next pointer,
leaving non-first xmlns attributes reachable in the properties list.
C14N then output them both as nsDef entries and as attributes.

close GH-21566
2026-03-31 22:27:01 +01:00
Niels Dossche f0f28b763c Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
2026-02-03 18:41:13 +01:00
Niels Dossche 52eb174ba6 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
2026-02-03 18:40:54 +01:00
Niels Dossche b8fc6bd1c8 Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
Split the handler again, or defer to instanceof when performance doesn't
matter.

Closes GH-21108.
2026-02-03 18:36:28 +01:00
Niels Dossche 0f4f73a254 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
2026-01-30 18:14:24 +01:00
Niels Dossche d54e5106b0 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
2026-01-30 18:14:19 +01:00
Niels Dossche d73b2f782e Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
Prior to this patch there was a common read handler, and it relied on
the dom class set in the intern document. However, Dom\Implementation
allows creating DTDs unassociated with a document, so we can't rely on
an intern document and the check fails. This causes the ZVAL_NULL() path
to be taken.
To solve this, just split the handler.

Closes GH-21082.
2026-01-30 18:13:55 +01:00
Niels Dossche 004934ce60 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20444: Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N()
2025-12-26 22:28:55 +01:00
Niels Dossche 31ae40d5e1 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20444: Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N()
2025-12-26 22:28:51 +01:00
Niels Dossche 40c291cf93 Fix GH-20444: Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N()
C14N code expects namespace to be in-tree, but we store namespaces in a
different way out-of-tree to avoid reconciliations that break the tree
structure in a way unexpected by the DOM spec. In the DOM spec,
namespace nodes don't exist; they're regular attributes.
To solve this, we temporarily make fake namespace nodes that we later
remove.

Closes GH-20457.
2025-12-26 22:27:25 +01:00
Niels Dossche f5024930cc Merge branch 'PHP-8.5'
* PHP-8.5:
  dom: Fix missing NUL byte check on C14NFile()
2025-11-13 00:04:04 +01:00
Niels Dossche abad39a42a Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  dom: Fix missing NUL byte check on C14NFile()
2025-11-13 00:03:56 +01:00
Niels Dossche a103251eb2 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  dom: Fix missing NUL byte check on C14NFile()
2025-11-13 00:03:36 +01:00
Niels Dossche 8ad5915756 dom: Fix missing NUL byte check on C14NFile()
Closes GH-20466.
2025-11-13 00:03:13 +01:00
Niels Dossche 618e576614 Minor DOM cleanups 2025-11-11 13:41:18 +01:00
Niels Dossche f2aaea053c Use faster string construction in ext/dom in some places (#20005)
Many tag names are single characters, so we can use the fast string
construction. In cases where a NULL name is used we can also use the
empty string.
This avoids some allocations and some work.
2025-09-30 18:10:24 +02:00
Tim Düsterhus f57e308e88 dom: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Niels Dossche 8526de84a5 Move common obj_map API functions to obj_map.c 2025-06-22 12:30:50 +02:00
Niels Dossche ff0a2cff05 Refactor implementation of DOM nodelists, named maps, and iterators
The code was really messy with lots of checks and inconsistencies.
This splits everything up into different functions and now everything is
relayed to a handler vtable.
2025-06-21 22:17:33 +02:00
Niels Dossche 1eacd4aea0 Avoid unnecessary string refcounting in ext/dom (#17889) 2025-02-23 00:23:22 +01:00
Niels Dossche 5471f117c5 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17500: Segfault with requesting nodeName on nameless doctype
2025-01-17 19:37:19 +01:00
Niels Dossche 525aeff070 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17500: Segfault with requesting nodeName on nameless doctype
2025-01-17 19:37:14 +01:00
Niels Dossche 82d71a82aa Fix GH-17500: Segfault with requesting nodeName on nameless doctype
Closes GH-17344.
2025-01-17 19:36:47 +01:00
Niels Dossche 7be3649016 Cleanup iterator instantiation code (#17358)
Just using object_init_ex() directly makes the code a bit simpler and
avoids unnecessary indirections.
2025-01-04 16:48:41 +01:00
Niels Dossche 59a0d00a5d Avoid string duplications in dom iterators 2025-01-03 17:50:01 +01:00
Niels Dossche b112d27ff5 [ci skip] Update last check date for compareDocumentPosition()
I validated there were no spec changes for this, so we can bump the last
check date.
2024-11-17 13:41:59 +01:00
Niels Dossche cfc8361fe6 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16777: Calling the constructor again on a DOM object after it is in a document causes UAF
  Fix GH-16808: Segmentation fault in RecursiveIteratorIterator->current() with a xml element input
2024-11-16 13:42:22 +01:00