Commit Graph

1242 Commits

Author SHA1 Message Date
Niels Dossche
4049594adf
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix UAF when removing doctype and using foreach iteration
2024-07-30 20:03:30 +02:00
Niels Dossche
b282dd749f
Fix UAF when removing doctype and using foreach iteration
This is an old bug, but this is pretty easy to fix.
It's basically applying the same fix as I did for e878b9f.
Reported by YuanchengJiang.

Closes GH-15143.
2024-07-30 20:01:22 +02:00
Niels Dossche
ecf0bb0fd1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Backport libxml2 2.13.2 fixes (#14816)
2024-07-04 15:37:35 +02:00
Niels Dossche
4fe821311c
Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-07-04 15:29:50 +02:00
Niels Dossche
0a1f51deb3
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14702: DOMDocument::xinclude() crash
2024-06-28 22:22:12 +02:00
Niels Dossche
42908f9f68
Fix GH-14702: DOMDocument::xinclude() crash
The xinclude code from libxml removes the fallback node,
but the fallback node is still reference via $fallback.
The solution is to detach the nodes that are going to be removed in
advance.

Closes GH-14704.
2024-06-28 22:21:12 +02:00
Niels Dossche
edc130910f
Fix build 2024-05-29 18:50:07 +02:00
Niels Dossche
fe0214bb55
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
2024-05-29 17:51:47 +02:00
Niels Dossche
88ff32a25b
Fix GH-14343: Memory leak in xml and dom (#14347)
If there is no root, the namespace cannot be attached to it,
so we have to attach it to the old list.

This isn't a problem in "new DOM" because namespaces are managed in a
separate structure there.
2024-05-29 17:49:07 +02:00
Niels Dossche
12ef6cc5a6
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix crash in ParentNode::append() when dealing with a fragment containing text nodes
2024-05-12 02:03:28 +02:00
Niels Dossche
1e2a2d7df2
Fix crash in ParentNode::append() when dealing with a fragment containing text nodes
Credits for test: https://github.com/PhpGt/Dom/pull/454.

Closes GH-14206.
2024-05-12 02:00:31 +02:00
Niels Dossche
59f16223ae
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix missing deref in C14N (#14203)
2024-05-11 17:13:12 +02:00
Niels Dossche
1890d47c51
Fix missing deref in C14N (#14203)
Follow-up for 30a0b0359e, which didn't fix
all places. This is the last remaining place.
2024-05-11 17:12:20 +02:00
Niels Dossche
461d890f0a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix crash when calling childNodes next() when iterator is exhausted
  Fix references not handled correctly in C14N
  Fix crashes when entity declaration is removed while still having entity references
2024-04-30 22:38:32 +02:00
Niels Dossche
2dbe2d62b3
Fix crash when calling childNodes next() when iterator is exhausted
Closes GH-14091.
2024-04-30 22:30:58 +02:00
Niels Dossche
30a0b0359e
Fix references not handled correctly in C14N
Closes GH-14090.
2024-04-30 22:30:28 +02:00
Niels Dossche
e878b9f390
Fix crashes when entity declaration is removed while still having entity references
libxml doesn't do reference counting inside its node types. It's
possible to remove an entity declaration out of the document, but then
entity references will keep pointing to that stale declaration. This
will cause crashes.

One idea would be to check when a declaration is removed, to trigger a
hook that updates all references. However this means we have to keep
track of all references somehow, which would be a high-overhead
solution. The solution in this patch makes sure that the fields are
always updated before they are read.

Closes GH-14089.
2024-04-30 22:29:44 +02:00
Vincent Langlet
741570c30f Fix phpdoc for DOMDocument load methods
Closes GH-13763.
2024-03-20 17:22:04 +01:00
Niels Dossche
0f79c22627 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix potential memory leak in XPath evaluation results
2024-03-14 21:11:19 +01:00
Niels Dossche
30c58aba0c Fix potential memory leak in XPath evaluation results 2024-03-14 21:08:25 +01:00
Niels Dossche
134464e451 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add ZPP checks in DOMNode::{__sleep,__wakeup}
2024-03-09 23:20:16 +01:00
Niels Dossche
e3711af8ce Add ZPP checks in DOMNode::{__sleep,__wakeup}
Closes GH-13651.
2024-03-09 23:19:49 +01:00
Niels Dossche
c5a63a90fa Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix reference access in dimensions for DOMNodeList and DOMNodeMap
2024-02-26 19:44:39 +01:00
Niels Dossche
b8a1041fd2 Fix reference access in dimensions for DOMNodeList and DOMNodeMap
Closes GH-13511.
2024-02-26 19:42:54 +01:00
Niels Dossche
ab508c98b3 Fix unlikely memory leak in case of namespace removal with extremely deep trees 2024-02-05 22:49:15 +01:00
Peter Kokot
8d5fc8d23f Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use EXTENSIONS instead of SKIPIF sections in *.phpt
2024-01-31 11:20:44 +01:00
Peter Kokot
218a93b898 Use EXTENSIONS instead of SKIPIF sections in *.phpt
This also fixes skipped tests due to different naming "zend-test"
instead of "zend_test" and "PDO" instead of "pdo":

- ext/dom/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/simplexml/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/xmlreader/tests/libxml_global_state_entity_loader_bypass.phpt
- ext/zend_test/tests/observer_sqlite_create_function.phpt

EXTENSIONS section is used for the Windows build to load the non-static
extensions.

Closes GH-13276
2024-01-31 11:18:21 +01:00
Niels Dossche
120bd364aa Fix crashes with entity references and predefined entities
Closes GH-13004.
2024-01-17 19:41:22 +01:00
Niels Dossche
93951cf5ab Fix GH-13012: DOMNode::isEqualNode() is incorrect when attribute order is different
Attributes (and namespace declarations) have to be compared in an
unordered way.

Closes GH-13017.
2023-12-27 02:22:23 +01:00
Niels Dossche
5f69232b53 Revert "Fix crashes with entity references and predefined entities"
This reverts commit 3fa5af8496.
2023-12-23 17:31:18 +01:00
Niels Dossche
3fa5af8496 Fix crashes with entity references and predefined entities
There's two issues here:
- freeing of predefined entity declaration crashes (unique to 8.3 & master)
- using multiple entity references for a single entity declaration crashes
  (since forever)

The fix for the last issue is fairly easy to do on 8.3, but may require a
slightly different approach on 8.2. Therefore, for now this is 8.3-only.

Closes GH-13004.
2023-12-23 17:00:57 +01:00
Niels Dossche
8e8d5ce240 Fix crash in adoptNode with attribute references
I forgot to also update the document reference of attributes, so when
there is no document reference anymore from a variable, but still an
attribute, this can crash. Fix it by also updating the document
references for attributes.

Closes GH-13002.
2023-12-23 16:58:11 +01:00
Niels Dossche
b2d778c36e Fix crash when toggleAttribute() is used without a document 2023-12-22 21:12:59 +01:00
Niels Dossche
e658f80501 Fix GH-12870: Creating an xmlns attribute results in a DOMException
There were multiple things here since forever, see the GH thread [1]
for discussion.

There were already many fixes to this function previously, and as a
consequence of one of those fixes this started throwing exceptions for a
correct use-case. It turns out that even when reverting to the previous
behaviour there are still bugs. Just fix all of them while we have the
chance.

[1] https://github.com/php/php-src/issues/12870

Closes GH-12888.
2023-12-07 22:42:32 +01:00
Niels Dossche
5be5a3dfdb Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Test fixes for libxml2 2.12.0
2023-11-29 20:53:13 +01:00
Niels Dossche
061058a9b1 Test fixes for libxml2 2.12.0 2023-11-29 20:52:01 +01:00
Niels Dossche
2b42b73c0b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12616: DOM: Removing XMLNS namespace node results in invalid default: prefix
  Fix GH-12702: libxml2 2.12.0 issue building from src
2023-11-17 19:58:31 +01:00
Niels Dossche
3167d07603 Fix GH-12616: DOM: Removing XMLNS namespace node results in invalid default: prefix
The namespace data is freed and set to NULL, but there remain references
to the namespace declaration nodes. This (rightfully) confuses libxml2
because its invariants are broken. We also have to remove all remaining
references from the subtree. This fixes the data corruption bug.

Closes GH-12681.
2023-11-17 19:47:08 +01:00
Niels Dossche
8a95e616b9 Fix GH-12702: libxml2 2.12.0 issue building from src
Fixes GH-12702.

Co-authored-by: nono303 <github@nono303.net>
2023-11-17 19:46:30 +01:00
Niels Dossche
ea299d44a1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix validation logic of php:function() callbacks in dom and xsl
2023-11-02 20:32:36 +01:00
Niels Dossche
304e482813 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix validation logic of php:function() callbacks in dom and xsl
2023-11-02 20:32:10 +01:00
Niels Dossche
20c9c4a367 Fix validation logic of php:function() callbacks in dom and xsl
Two issues:
- Assumed that at least 1 argument (function name) was provided.
- Incorrect error path for the non-callable case.

Closes GH-12593.
2023-11-02 20:28:55 +01:00
Niels Dossche
f9a24969d0 Fix #47531: No way of removing redundant xmlns: declarations
Now it's possible via removeAttribute("xmlns:prefix").
It was not possible to reuse a libxml2 function to reconcile because it
does not align with DOM behaviour.

Closes GH-12542.
2023-10-28 15:46:22 +02:00
Niels Dossche
a64b48ba92 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Fix null pointer dereferences in case of allocation failure
2023-10-24 19:42:43 +02:00
Niels Dossche
dd8a945eb7 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix null pointer dereferences in case of allocation failure
2023-10-24 19:36:57 +02:00
icy17
900f0cab9f Fix null pointer dereferences in case of allocation failure
Closes GH-12506.
2023-10-24 19:34:47 +02:00
Niels Dossche
f5d1a194d9 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix registerNodeClass with abstract class crashing
2023-10-13 19:10:51 +02:00
Niels Dossche
a025e6c780 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix registerNodeClass with abstract class crashing
2023-10-13 19:08:13 +02:00
Niels Dossche
d7de0ceca6 Fix registerNodeClass with abstract class crashing
This always results in a segfault when trying to instantiate, so this never
worked. At least throw an error instead of segfaulting to prevent developers
from being confused.

Closes GH-12420.
2023-10-13 19:06:09 +02:00
Niels Dossche
58a1103bee Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-8996: DOMNode serialization on PHP ^8.1
  Fix GH-12380: JIT+private array property access inside closure accesses private property in child class
2023-10-09 22:12:05 +02:00