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

275 Commits

Author SHA1 Message Date
Ilija Tovilo
685bd9de81 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Suppress libxml deprecations
2025-12-02 16:41:37 +01:00
Ilija Tovilo
26b9395ad6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Suppress libxml deprecations
2025-12-02 16:38:08 +01:00
Ilija Tovilo
f7fb13eb07 Suppress libxml deprecations
Closes GH-20538
2025-12-02 16:37:50 +01:00
Niels Dossche
8c2407714f libxml: Fix input buffer deprecation
While this fixed the last deprecation in ext/libxml, it's not a full
fix: The full fix would be to move to the context-specific APIs to
override the behaviour. However, that requires API/ABI incompatible
changes so that can't be done on a stable branch.

Closes GH-20525.
2025-11-19 18:41:28 +01:00
Niels Dossche
6054a900ff libxml: Fix some deprecations regarding input buffer/parser handling
Closes GH-20514.
2025-11-18 18:53:17 +01:00
Niels Dossche
f3cb9a81fb Wrap the normally lazy-initialized components in ZTS 2025-10-14 22:14:54 +02:00
Niels Dossche
75d8449d1f Fix not thread safe RelaxNG invocations in ZTS builds 2025-10-14 22:00:24 +02:00
SpencerMalone
f14e5fcfbd Fix not thread safe xmlSchemaParse calls in ZTS builds
By calling xmlSchemaInitTypes during MINIT.
See: https://gitlab.gnome.org/GNOME/libxml2/-/issues/930

Closes GH-20150.
2025-10-14 21:59:46 +02:00
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
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
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
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
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
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
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
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
Niels Dossche
82b05373b1 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11160: Few tests failed building with new libxml 2.11.0
2023-05-06 23:15:57 +02:00
Niels Dossche
dc1a70c244 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11160: Few tests failed building with new libxml 2.11.0
2023-05-06 23:10:58 +02:00
Niels Dossche
7c0dfc5cf5 Fix GH-11160: Few tests failed building with new libxml 2.11.0
It's possible to categorise the failures into 2 categories:
  - Changed error message. In this case we either duplicate the test and
    modify the error message. Or if the change in error message is
    small, we use the EXPECTF matchers to make the test compatible with both
    old and new versions of libxml2.
  - Missing warnings. This is caused by a change in libxml2 where the
    parser started using SAX APIs internally [1]. In this case the
    error_type passed to php_libxml_internal_error_handler() changed from
    PHP_LIBXML_ERROR to PHP_LIBXML_CTX_WARNING because it internally
    started to use the SAX handlers instead of the generic handlers.
    However, for the SAX handlers the current input stack is empty, so
    nothing is actually printed. I fixed this by falling back to a
    regular warning without a filename & line number reference, which
    mimicks the old behaviour. Furthermore, this change now also shows
    an additional warning in a test which was previously hidden.

[1] 9a82b94a94

Closes GH-11162.
2023-05-06 23:10:07 +02:00
Max Kellermann
1287747a9a ext: make various internal functions static (#10650)
Namely in:
* ext/date
* ext/libxml
* ext/dba
* ext/curl
2023-02-21 15:51:41 +00:00
George Peter Banyard
32d3cae19f Handle trampolines correctly in new FCC API + usages (#9877) 2022-11-22 17:12:53 +00:00
George Peter Banyard
fb114bf45b Only use FCC for libxml entity loader callback 2022-11-02 14:52:54 +00:00
Tim Starling
11796229f2 Add libxml_get_external_entity_loader()
Add libxml_get_external_entity_loader(), which returns the currently
installed external entity loader, i.e. the value which was passed to
libxml_set_external_entity_loader() or null if no loader was installed
and the default entity loader will be used.

This allows libraries to save and restore the loader, controlling entity
expansion without interfering with the rest of the application.

Add macro Z_PARAM_FUNC_OR_NULL_WITH_ZVAL(). This allows us to get the
zval for a callable parameter without duplicating callable argument
parsing.

The saved zval keeps the object needed for fcc/fci alive, simplifying
memory management.

Fixes #76763.
2022-08-28 12:47:20 +01:00
Christoph M. Becker
145525bc4c Merge branch 'PHP-8.1'
* PHP-8.1:
  xmlRelaxNGCleanupTypes() is deprecated as of libxml2 2.10.0
2022-08-25 15:12:40 +02:00
Christoph M. Becker
afc5ab4531 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  xmlRelaxNGCleanupTypes() is deprecated as of libxml2 2.10.0
2022-08-25 15:11:41 +02:00
Christoph M. Becker
f59754694e xmlRelaxNGCleanupTypes() is deprecated as of libxml2 2.10.0
The documentation[1] suggest to call `xmlCleanupParser()` instead, but
we are not doing that for reasons[2].  Thus, we do no longer call
`xmlRelaxNGCleanupTypes()` for libxml2 ≥ 2.10.0.

[1] <https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/libxml2-relaxng.html#xmlRelaxNGCleanupTypes>
[2] <8742276eb3>

Closes GH-9417.
2022-08-25 15:10:30 +02:00
Máté Kocsis
7601068f3d Declare ext/libxml constants in stubs (#8721) 2022-06-09 08:18:44 +02:00
Ilija Tovilo
2f5295692f Optimize stripos/stristr
Closes GH-7847
Closes GH-7852

Previously stripos/stristr would lowercase both the haystack and the
needle to reuse strpos. The approach in this PR is similar to strpos.
memchr is highly optimized so we're using it to search for the first
character of the needle in the haystack. If we find it we compare the
remaining characters of the needle manually.

The new implementation seems to perform about half as well as strpos (as
two memchr calls are necessary to find the next candidate).
2022-01-31 21:44:31 +01:00
Stanislav Malyshev
9de4eb9e37 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #79971: special character is breaking the path in xml function
2021-11-14 23:29:59 -08:00
Stanislav Malyshev
9d74c5b40b Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #79971: special character is breaking the path in xml function
2021-11-14 23:29:37 -08:00
Stanislav Malyshev
0ef1dfc9f6 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #79971: special character is breaking the path in xml function
2021-11-14 23:29:27 -08:00