1
0
mirror of https://github.com/php/php-src.git synced 2026-03-25 16:52:18 +01:00
Commit Graph

280 Commits

Author SHA1 Message Date
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
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
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
Niels Dossche
d3fada3748 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  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:14 +01:00
Niels Dossche
18b18f0ee0 Fix GH-16777: Calling the constructor again on a DOM object after it is in a document causes UAF
Closes GH-16824.
2024-11-16 13:42:01 +01:00
Niels Dossche
7f5a888bdb Change dom_node_is_read_only() to return bool (#16757)
Returning int or zend_result doesn't make sense, it's a yes/no question.
2024-11-11 20:57:52 +01:00
Niels Dossche
6e82ae9990 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16595: Another UAF in DOM -> cloneNode
  Fix GH-16593: Assertion failure in DOM->replaceChild
2024-10-28 19:45:22 +01:00
Niels Dossche
ed21ebd8aa Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16595: Another UAF in DOM -> cloneNode
  Fix GH-16593: Assertion failure in DOM->replaceChild
2024-10-28 19:39:24 +01:00
Niels Dossche
9d8983c061 Fix GH-16595: Another UAF in DOM -> cloneNode
We need to perform all sanity checks before doing any modification.
I don't have a reliable and easy test for this on 8.2, but I have one
for 8.4.

Closes GH-16598.
2024-10-28 19:37:08 +01:00
Niels Dossche
d89dd28d3b Fix GH-16593: Assertion failure in DOM->replaceChild
This is already forbidden by libxml, but this condition isn't properly
checked; so the return value and lack of error makes it seem like it
worked while it actually didn't. Furthermore, this can break assumptions
and assertions later on.

Closes GH-16596.
2024-10-28 19:36:29 +01:00
Niels Dossche
a0266920e4 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16535: UAF when using document as a child
  Fix GH-16533: Segfault when adding attribute to parent that is not an element
2024-10-21 20:57:42 +02:00
Niels Dossche
5a09e0105e Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16535: UAF when using document as a child
  Fix GH-16533: Segfault when adding attribute to parent that is not an element
2024-10-21 20:57:22 +02:00
Niels Dossche
51b642f2c9 Fix GH-16535: UAF when using document as a child
Documents can never be children of any node.

Closes GH-16539.
2024-10-21 20:56:14 +02:00
Niels Dossche
a0a7361b64 Fix GH-16533: Segfault when adding attribute to parent that is not an element
Attributes are only valid as children of elements. This bug goes back
all the way.

Closes GH-16537.
2024-10-21 20:55:42 +02:00
Niels Dossche
81a2cd4dac Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix various document ref pointer mismanagements
2024-10-17 21:21:49 +02:00
Niels Dossche
5cb38e9d24 Fix various document ref pointer mismanagements
- Properly handle attributes
- Fix potential NULL dereference if the intern document pointer is NULL

Fixes GH-16336.
Fixes GH-16338.
Closes GH-16345.
2024-10-17 21:18:50 +02:00
Niels Dossche
b7b0b954be Restore accidentally deleted check 2024-10-12 13:41:24 +02:00
Niels Dossche
c31eac7284 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add missing hierarchy checks to replaceChild
  Fix GH-16337: Use-after-free in SplHeap
2024-10-12 13:39:06 +02:00
Niels Dossche
3ed01d454d Add missing hierarchy checks to replaceChild
You can break the hierarchy for attribute nodes, use the helper function
introduced recently [1] to fix this issue.

[1] 066d18f2

Closes GH-16377.
2024-10-12 13:32:13 +02:00
Niels Dossche
ba0834bc2c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix bugs GH-16150 and GH-16152: intern document mismanagement
2024-10-03 19:33:09 +02:00
Niels Dossche
d4a4d2e7a9 Fix bugs GH-16150 and GH-16152: intern document mismanagement
The reference counts of the internal document pointer are mismanaged.
In the case of fragments the refcount may be increased too much, while
for other cases the document reference may not be applied to all
children.

This bug existed for a long time and this doesn't reproduce (easily)
on 8.2 due to other bugs. Furthermore 8.2 will enter security mode soon,
and this change may be too risky.

Fixes GH-16150.
Fixed GH-16152.
Closes GH-16178.
2024-10-03 19:28:50 +02:00
Niels Dossche
3be6ff66b8 Fix GH-16190: Using reflection to call Dom\Node::__construct causes assertion failure
Closes GH-16193.
2024-10-03 19:25:58 +02:00
Niels Dossche
341c26fc3f Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
2024-10-01 21:47:52 +02:00
Niels Dossche
cd67c090a9 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
2024-10-01 21:47:26 +02:00
Niels Dossche
066d18f2e8 Fix GH-16151: Assertion failure in ext/dom/parentnode/tree.c
Unfortunately, old DOM allows attributes to be used as parent nodes.
Only text nodes and entities are allowed as children for these types of
nodes, because that's the constraint DOM and libxml give us.

Closes GH-16156.
2024-10-01 21:46:12 +02:00
Niels Dossche
067eb8c0d7 [ci skip] Remove confusing comments
They are readonly / not readonly depending on the class where they're used.
However, the comment makes this confusing [1].

[1] https://github.com/php/php-src/issues/15578#issuecomment-2310389300
2024-08-27 22:24:39 +02:00
Niels Dossche
2cfcfe09a0 Convert more common methods in dom/node.c to fast ZPP (#15043) 2024-07-20 20:20:32 +02:00
Niels Dossche
80a4783d25 Deduplicate NULL checks in ext/dom (#15015)
This introduces a new helper php_dom_create_nullable_object() that does
the NULL check and puts NULL in return_value. Otherwise it runs
php_dom_create_object(). This deduplicates a bit of code.
2024-07-18 21:20:03 +02:00
Niels Dossche
6980eba863 Support templated content
The template element in HTML 5 is special in the sense that it does not
add its contents into the DOM tree, but instead keeps them in a separate
shadow DOM document fragment. Interacting with the DOM tree cannot touch
the elements in the document fragment.

Closes GH-14906.
2024-07-15 11:10:51 +02:00
Niels Dossche
4ef7539144 Split off private data from the ns mapper 2024-07-15 11:02:52 +02:00
Niels Dossche
768900b180 Implement Dom $innerHTML property 2024-07-02 11:15:38 -07:00
Niels Dossche
c66221b7ba Fix arginfo violation in removeChild() (#14717)
It was possible to return false without throwing an exception.
This is even wrong in "old DOM" because we expect either a NOT_FOUND_ERR
or NO_MODIFICATION_ALLOWED_ERR according to the documentation.
A side effect of this patch is that it prioritises NOT_FOUND_ERR over
NO_MODIFICATION_ALLOWED_ERR but I think that's fine.
2024-06-29 16:32:36 +02:00
Arnaud Le Blanc
11accb5cdf Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Niels Dossche
8dc2391bae Fix bug #79701: getElementById does not correctly work with duplicate definitions
This is a long standing bug: IDs aren't properly tracked causing either
outdated or plain incorrect results from getElementById.

This PR implements a pragmatic solution in which we still try to use the
ID lookup table to a degree, but only as a performance boost not as a
"single source of truth". Full details are explained in the
getElementById code.

Closes GH-14349.
2024-06-01 12:55:05 +02:00
Niels Dossche
eeae9875f8 Avoid narrowing 2024-05-13 19:46:51 +02:00
Niels Dossche
1d573000d5 Remove unused arguments 2024-05-13 19:46:51 +02:00
Niels Dossche
e7af2bfd5b Get rid of reserved name usage 2024-05-13 19:46:51 +02:00
Niels Dossche
de4c9c3398 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix missing deref in C14N (#14203)
2024-05-11 17:13:20 +02:00