1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Commit Graph

433 Commits

Author SHA1 Message Date
Niels Dossche
312869381a Fix GH-19098: libxml<2.13 segmentation fault caused by php_libxml_node_free
This implements a workaround for reconciliation not being performed for
document-less nodes in libxml<2.13.

Closes GH-19186.
2025-07-20 17:19:43 +02:00
Gina Peter Banyard
61f704f269 ext/libxml: Fixed custom external entity loader returning an invalid resource leading to a confusing TypeError message
Closes GH-18096
2025-04-07 12:58:52 +01:00
Jakub Zelenka
acf2f4988a Merge branch 'PHP-8.2' into PHP-8.3 2025-03-11 22:09:00 +01:00
Jakub Zelenka
4af1830356 Merge branch 'PHP-8.1' into PHP-8.2 2025-03-11 21:57:33 +01:00
Tim Düsterhus
b6004a043c Fix GHSA-p3x9-6h7p-cgfc: libxml streams wrong content-type on redirect
libxml streams use wrong content-type header when requesting a
redirected resource.
2025-03-11 21:50:17 +01:00
Niels Dossche
7be950f3f6 Fix GH-17223: Memory leak in libxml encoding handling
This was a bug in both libxml and PHP.
We follow up with the same change as done in GNOME/libxml@b3871dd138.

Changing away from `xmlOutputBufferCreateFilenameDefault` is not
possible yet because this is a stable branch and would break BC.

Closes GH-17254.
2024-12-26 12:24:06 +01:00
Niels Dossche
6199289b6e Backport 3ec5919e: Update error message for libxml 2.13
External entity loading got its error level decreased in upstream,
which means they now map to E_NOTICE. Also the error message format has
changed.
2024-10-12 15:12:40 +02:00
Niels Dossche
b78618750f Backport f74f9b07: Update libxml test for the directory field behaviour change
See https://gitlab.gnome.org/GNOME/libxml2/-/issues/753.
The base directory for the entity is no longer set, follow the upstream
behaviour.
2024-10-12 15:12:40 +02:00
Niels Dossche
bb46b4b799 Backport 4fe82131: Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-10-12 15:12:40 +02:00
Niels Dossche
dbde99d875 Backport e2d97314: Backport deprecation warning ignores to unbreak CI
In master I use ZEND_DIAGNOSTIC_IGNORED_START, but that doesn't exist on
8.2 or 8.3 (8.3 has a similar macro though).
So to unbreak CI I just made a variation of this directly in the
php_libxml.h header.

See 683e787860 (commitcomment-134301083)
2024-10-12 15:12:40 +02:00
Niels Dossche
fa6a0f80f6 Backport 0a39890c: Fix libxml2 2.12 build due to API breaks
See https://github.com/php/php-src/actions/runs/7062192818/job/19225478601
2024-10-12 15:12:40 +02:00
Niels Dossche
79427ae08e Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Update error message for libxml 2.13
  Update libxml test for the directory field behaviour change
2024-09-12 23:07:12 +02:00
Niels Dossche
3ec5919e14 Update error message for libxml 2.13
External entity loading got its error level decreased in upstream,
which means they now map to E_NOTICE. Also the error message format has
changed.
2024-09-12 23:06:25 +02:00
Niels Dossche
f74f9b073a Update libxml test for the directory field behaviour change
See https://gitlab.gnome.org/GNOME/libxml2/-/issues/753.
The base directory for the entity is no longer set, follow the upstream
behaviour.
2024-09-12 23:06:25 +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
b63b100e36 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14563: Build failure with libxml2 v2.13.0
2024-06-29 16:28:51 +02:00
Niels Dossche
b08def5156 Fix GH-14563: Build failure with libxml2 v2.13.0
Remove xmlErrMemory from the export section for Windows, this fixes the
build. Even though the original function was renamed [1] it is hidden,
so removing this should be sufficient and not be a BC break.

[1] 130436917c

Closes GH-14719.
2024-06-29 16:28:16 +02: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
5f69232b53 Revert "Fix crashes with entity references and predefined entities"
This reverts commit 3fa5af8496.
2023-12-23 17:31:18 +01:00
Niels Dossche
bb007438e2 Fix libxml2 build for 2.12.0-2.12.2 2023-12-23 17:20:52 +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
f3ee902c3d Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Backport deprecation warning ignores to unbreak CI
2023-12-06 22:18:12 +01:00
Niels Dossche
e2d97314ab Backport deprecation warning ignores to unbreak CI
In master I use ZEND_DIAGNOSTIC_IGNORED_START, but that doesn't exist on
8.2 or 8.3 (8.3 has a similar macro though).
So to unbreak CI I just made a variation of this directly in the
php_libxml.h header.

See 683e787860 (commitcomment-134301083)

Closes GH-12887.
2023-12-06 22:17:27 +01:00
Niels Dossche
f61f8d439c Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix libxml2 2.12 build due to API breaks
2023-12-01 18:07:13 +01:00
Niels Dossche
0a39890c96 Fix libxml2 2.12 build due to API breaks
See https://github.com/php/php-src/actions/runs/7062192818/job/19225478601
2023-12-01 18:03:37 +01:00
Niels Dossche
6a76e5d0a2 Fix GH-12702: libxml2 2.12.0 issue building from src
Fixes GH-12702.

Co-authored-by: nono303 <github@nono303.net>
2023-11-22 20:39:30 -06: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
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
0cab865275 Fix compile error when php_libxml.h is included in C++
See https://github.com/php/pecl-xml-xmldiff/issues/1
2023-10-15 11:48:14 +02:00
Niels Dossche
d3273c13cb Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] Add xml and simplexml dependency to EXTENSIONS section in test
2023-10-07 21:14:24 +02:00
Niels Dossche
325b2b4a56 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] Add xml and simplexml dependency to EXTENSIONS section in test
2023-10-07 21:13:47 +02:00
Niels Dossche
6bb536e3f6 [ci skip] Add xml and simplexml dependency to EXTENSIONS section in test 2023-10-07 21:13:30 +02:00
Niels Dossche
eebc528cbf Fix broken cache invalidation with deallocated and reallocated document node
The original caching implementation had an oversight in combination with
the new lifetime management in DOM for 8.3.
The modification counter is stored on the document object itself, but as
that can get deallocated when all references disappear, stale cache data
can be used. Normally this isn't a problem, unless getElementsByTagName is
called not on the document but on a child node. Fix it by moving caching
data into the ref object, which will outlive all nodes from a document
even if the document object disappears.

Closes GH-12338.
2023-10-01 17:06:02 +02:00
Niels Dossche
df89409aba Fix compile error with -Werror=incompatible-function-pointer-types and old libxml2
libxml2 prior to 2.9.8 had a different signature for xmlHashScanner.
This signature changed in e03f0a199a
Use an #if to work around the incompatible signature.

Closes GH-12326.
2023-09-30 00:12:20 +02:00
Niels Dossche
6a2b885155 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Restore old namespace reconciliation behaviour
2023-09-27 22:40:37 +02:00
David CARLIER
e648d39e3b libxml set error structure simplification proposal (#12054) 2023-08-26 12:11:50 +01:00
Niels Dossche
e1cb721679 Improve warning when returning null from the resolver set by libxml_set_external_entity_loader
Fixes GH-11952.
Closes GH-12022.
2023-08-24 21:23:29 +02:00
Niels Dossche
bb092ab4c6 Fix #80927: Removing documentElement after creating attribute node: possible use-after-free
Closes GH-11892.
2023-08-12 18:49:12 +02:00
Niels Dossche
5018dfecdf Remove useless hashmap check
php_libxml_unlink_entity is called from a hashmap iterator, so using
xmlHashLookup to check if it comes from that hashmap will always be
true.
2023-08-07 19:53:20 +02:00
Derick Rethans
86afbe10e2 Merge branch 'PHP-8.2' 2023-07-31 19:57:02 +01:00
Derick Rethans
deddf4692a Merge branch 'PHP-8.1' into PHP-8.2 2023-07-31 19:54:44 +01:00
Derick Rethans
0870ebb862 Merge branch 'PHP-8.0' into PHP-8.1 2023-07-31 19:53:43 +01:00
Niels Dossche
c283c3ab0b Sanitize libxml2 globals before parsing
Fixes GHSA-3qrf-m4j2-pcrr.

To parse a document with libxml2, you first need to create a parsing context.
The parsing context contains parsing options (e.g. XML_NOENT to substitute
entities) that the application (in this case PHP) can set.
Unfortunately, libxml2 also supports providing default set options.
For example, if you call xmlSubstituteEntitiesDefault(1) then the XML_NOENT
option will be added to the parsing options every time you create a parsing
context **even if the application never requested XML_NOENT**.

Third party extensions can override these globals, in particular the
substitute entity global. This causes entity substitution to be
unexpectedly active.

Fix it by setting the parsing options to a sane known value.
For API calls that depend on global state we introduce
PHP_LIBXML_SANITIZE_GLOBALS() and PHP_LIBXML_RESTORE_GLOBALS().
For other APIs that work directly with a context we introduce
php_libxml_sanitize_parse_ctxt_options().
2023-07-31 19:47:19 +01:00
George Peter Banyard
a17e84f2f7 libxml_get_external_entity_loader(): test for incompatible resource being loaded (#11728)
A stream resource is expected to be returned by the handler.
2023-07-21 11:56:15 +01:00
Remi Collet
fde4386648 cast _private to avoid [-fpermissive] error 2023-07-20 07:55:01 +02:00
Niels Dossche
75229cb127 Cleanup php_libxml_node_decrement_resource()
obj_node is already checked, so checking it again in the second if is
not necessary.
Merge declarations and assignments while we're at it.
2023-07-11 11:47:54 +02:00
Niels Dossche
003ebdd039 Fix GH-9628: Implicitly removing nodes from \DOMDocument breaks existing references
Change the way lifetime works in ext/libxml and ext/dom

Previously, a node could be freed even when holding a userland reference
to it. This resulted in exceptions when trying to access that node after
it has been implicitly or explicitly removed. After this patch, a node
will only be freed when the last userland reference disappears.

Fixes GH-9628.
Closes GH-11576.
2023-07-03 21:31:57 +02:00
Niels Dossche
50b4df18e0 Get rid of return value for php_libxml_unregister_node() (#11398) 2023-06-08 17:44:55 +02:00
Niels Dossche
c3f0797385 Implement iteration cache, item cache and length cache for node list iteration (#11330)
* Implement iteration cache, item cache and length cache for node list iteration

The current implementation follows the spec requirement that the list
must be "live". This means that changes in the document must be
reflected in the existing node lists without requiring the user to
refetch the node list.
The consequence is that getting any item, or the length of the list,
always starts searching from the root element of the node list. This
results in O(n) time to get any item or the length. If there's a for
loop over the node list, this means the iterations will take O(n²) time
in total. This causes real-world performance issues with potential for
downtime (see GH-11308 and its references for details).

We fix this by introducing a caching strategy. We cache the last
iterated object in the iterator, the last requested item in the node
list, and the last length computation. To invalidate the cache, we
simply count the number of modifications made to the containing
document. If the modification number does not match what the number was
during caching, we know the document has been modified and the cache is
invalid. If this ever overflows, we saturate the modification number and
don't do any caching anymore. Note that we don't check for overflow on
64-bit systems because it would take hundreds of years to overflow.

Fixes GH-11308.
2023-06-03 00:13:14 +02:00