826 Commits
Author SHA1 Message Date
Ilija Tovilo 9705fda1bb Merge branch 'PHP-8.6' into master
* PHP-8.6:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:34:56 +02:00
Ilija Tovilo d6373dfe15 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:33:23 +02:00
Ilija Tovilo c7273b9ba8 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:30:04 +02:00
Ilija Tovilo 8a94bb3822 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:27:03 +02:00
Ilija Tovilo c1a5f468d0 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:12:35 +02:00
3584a98bda Avoid state corruption via bailout
- Replace bailout on OOM with UnwindExit
- Properly reset various globals that may be accessed during startup

Fix GHSA-w8hw-w9fx-j79w (CVE-2026-109618)
Fix GHSA-6wmf-4rv5-p3rp (CVE-2026-109619)

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Jakub Zelenka <bukka@php.net>
Co-authored-by: Nora Dossche <7771979+ndossche@users.noreply.github.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
2026-10-21 16:06:22 +02:00
Marc Bennewitz 5ec9164e59 Fix Bug-81481 XML_GetCurrentByteIndex() truncation on Windows x64
The fix for https://bugs.php.net/bug.php?id=81481 made the libxml
compatibility wrapper return long, which is still 32-bit on Windows x64,
so byte indexes beyond 2 GiB turned negative there. Return zend_long
instead and run the test on Windows too.

Closes GH-23901.
2026-10-05 19:42:59 +02:00
Gina Peter Banyard 4ee2e893f6 xml: use new zend_object_copy() API 2026-10-01 12:43:56 +01:00
Weilin Du 0c141af96a Merge branch 'PHP-8.4' into PHP-8.5
Propagate the backport of PR #23818 from PHP-8.4 to PHP-8.5.

* PHP-8.4:
  Backport: reject XML handler changes while parsing (#23818)
2026-09-22 01:53:16 +08:00
jvoisin b4c67a022a Backport: reject XML handler changes while parsing (#23818)
Backport PR #23818 from master to PHP-8.4.
Original commit: 522b1be810

The SAX handler setters store their callback as a zend_fcall_info_cache on
the parser and xml_set_handler() releases the previous one with
zend_fcc_dtor(). None of the setters checked parser->isparsing, so calling
xml_set_element_handler() (or any xml_set_*_handler()) from inside a running
handler freed the fcc that was still executing. For a non-closure
[$object, 'method'] handler whose object is only referenced by that fcc, the
zend_fcc_dtor() releases the last reference and frees $this while its method
is still on the stack, leading to a use-after-free.

Guard xml_set_element_handler() and the XML_SET_HANDLER_PHP_FUNCTION setters
with the existing isparsing flag and throw "Cannot change handlers while
parsing", mirroring the checks already used by xml_parser_set_option() and
xml_parse(). The parsed fcc is released on the error path like the other
failure branches.

Closes #23818
2026-09-22 01:53:14 +08:00
Julien Voisin 522b1be810 ext/xml: reject changing handlers while parsing (#23818)
The SAX handler setters store their callback as a zend_fcall_info_cache on
the parser and xml_set_handler() releases the previous one with
zend_fcc_dtor(). None of the setters checked parser->isparsing, so calling
xml_set_element_handler() (or any xml_set_*_handler()) from inside a running
handler freed the fcc that was still executing. For a non-closure
[$object, 'method'] handler whose object is only referenced by that fcc, the
zend_fcc_dtor() releases the last reference and frees $this while its method
is still on the stack, leading to a use-after-free.

Guard xml_set_element_handler() and the XML_SET_HANDLER_PHP_FUNCTION setters
with the existing isparsing flag and throw "Cannot change handlers while
parsing", mirroring the checks already used by xml_parser_set_option() and
xml_parse(). The parsed fcc is released on the error path like the other
failure branches.
2026-09-21 16:36:23 +01:00
Dmytro Kulyk 67135cb97b gen_stub: Conditionally include zend_attributes.h to arginfo based on usage (#21570)
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.

Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
2026-09-06 21:25:20 +02:00
NickSdot 8551dc60f1 ext/xml: applied fixers to improve test robustness (#23025) 2026-08-14 17:20:49 +08:00
Tim Düsterhus 69e023fd84 ext/*: Make X_from_obj(zend_object *obj) functions macros (#22183)
* ext/*: Make `X_from_obj(zend_object *obj)` functions macros

With the introduction of the `ZEND_CONTAINER_OF()` macro we can now preserve
whether or not the `zend_object *` is `const` when extracting the
class-specific struct. This change will allow to use `const zend_object *` in
more locations.

Changes performed with Coccinelle followed by some manual cleanup for comment
and whitespace formatting:

    @a@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, std); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, std)

    @@
    identifier a.f;
    @@

    - f(...) { ... }

    @b@
    attribute name zend_always_inline;
    type T;
    identifier obj;
    identifier f;
    typedef zend_object;
    @@

     T* f(zend_object *obj) { return ZEND_CONTAINER_OF(obj, T, zo); }
    + #define f(obj) ZEND_CONTAINER_OF(obj, T, zo)

    @@
    identifier b.f;
    @@

    - f(...) { ... }

* sockets: Fix build

* odbc: Fix build
2026-06-01 10:21:03 +02:00
Tim Düsterhus ad7cce6527 zend_portability: Add ZEND_CONTAINER_OF() (#21903)
* zend_portability: Add `ZEND_CONTAINER_OF()`

* tree-wide: Use `ZEND_CONTAINER_OF()`

Changes made with Coccinelle:

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    @@

    - (const T_container *)(((char *)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

    @@
    type T_container;
    identifier member;
    expression e;
    typedef uintptr_t;
    @@

    - (const T_container *)(((uintptr_t)(e)) - offsetof(T_container, member))
    + ZEND_CONTAINER_OF(e, T_container, member)

* bcmath: Fix `get_bcmath_number_from_obj()` const-correctness

A follow-up change to the new `ZEND_CONTAINER_OF()` macro will preserve the
`const`-ness of the input pointer. By wrapping this macro inside a macro rather
an an inline function we can preserve the `const`-ness across all layers.

* zend_portability: Keep `const`-ness in `ZEND_CONTAINER_OF()`

* zend_portability: Add C++ version to `ZEND_CONTAINER_OF()`
2026-05-19 10:47:00 +02:00
David Carlier 51911cc1c6 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/xml: Use zend_string_safe_realloc() for cdata concatenation.
2026-05-16 18:53:05 +01:00
David Carlier c8c48f5e9c Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/xml: Use zend_string_safe_realloc() for cdata concatenation.
2026-05-16 18:52:54 +01:00
David Carlier d5a57af4e2 ext/xml: Use zend_string_safe_realloc() for cdata concatenation.
The previous code computed `Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value)`
as a plain `size_t` addition before passing the result to
zend_string_extend(), which can wrap on 32-bit and lead to a heap
overflow in the following strncpy(). Switch to zend_string_safe_realloc()
so the size computation is bounds-checked.

close GH-22056
2026-05-16 18:52:31 +01:00
Tim Düsterhus 7114314c5a tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an
unnecessary layer of indirection.
2026-04-28 22:12:56 +02:00
Ben Ramsey c3e63ae942 license-update: ext/xml source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Arshid e5f9650d7a ext/xml: Use zend_hash_lookup() for missing array keys (#21536) 2026-03-26 22:27:30 +01:00
Weilin Du 2918caee20 ext/*: Remove break after return (#21485) 2026-03-23 20:30:13 +01:00
Peter Kokot f17c5ad83b Windows build: Add new function CHECK_HEADER() (#21191)
The current function `CHECK_HEADER_ADD_INCLUDE()` automatically defines
`HAVE_<HEADER_NAME_H>` preprocessor macros, which makes it difficult to
sync with other build systems. Specially, if some `HAVE_` macro is used
in the code and this function defines this macro but Autotools doesn't.

The new `CHECK_HEADER()` function behaves similar except it doesn't
define the `HAVE_<HEADER_NAME_H>` preprocessor macro.

This removes the following unused compile definitions:

HAVE_ARGON2_H
HAVE_AVIF_H
HAVE_BZLIB_H
HAVE_CAPSTONE_CAPSTONE_H
HAVE_CURL_EASY_H
HAVE_DB_H
HAVE_DECODE_H
HAVE_DEPOT_H
HAVE_EDITLINE_READLINE_H
HAVE_ENCHANT_H
HAVE_ENCODE_H
HAVE_FFI_H
HAVE_FIREBIRD_INTERFACE_H
HAVE_FT2BUILD_H
HAVE_GD_H
HAVE_GLIB_H
HAVE_GMP_H
HAVE_HTTPD_H
HAVE_IBASE_H
HAVE_IR_IR_H
HAVE_KECCAKHASH_H
HAVE_LBER_H
HAVE_LDAP_H
HAVE_LIBEXSLT_EXSLT_H
HAVE_LIBINTL_H
HAVE_LIBPQ_FE_H
HAVE_LIBTIDY_TIDY_H
HAVE_LIBXML_PARSER_H
HAVE_LIBXML_TREE_H
HAVE_LIBXML_XMLWRITER_H
HAVE_LIBXSLT_XSLT_H
HAVE_LMDB_H
HAVE_MBSTRING_H
HAVE_MYSQL_H
HAVE_ONIGURUMA_H
HAVE_OPENSSL_SSL_H
HAVE_PNG_H
HAVE_SNMP_H
HAVE_SODIUM_H
HAVE_SQLITE3_H
HAVE_SQLITE3EXT_H
HAVE_SYBFRONT_H
HAVE_TIDY_H
HAVE_TIDY_TIDY_H
HAVE_TIDYBUFFIO_H
HAVE_TIMELIB_CONFIG_H
HAVE_UNICODE_USPOOF_H
HAVE_UNICODE_UTF_H
HAVE_XPM_H
HAVE_ZIP_H
HAVE_ZIPCONF_H
HAVE_ZLIB_H

The following compile definitions are defined explicitly:

- HAVE_ICONV_H
- HAVE_MSCOREE_H
- HAVE_SQL_H
- HAVE_SQLEXT_H

Additionally, the `SETUP_OPENSSL()` function doesn't accept the 6th
argument anymore.
2026-03-03 20:06:40 +01:00
Ilija Tovilo 073dcf66bb Merge branch 'PHP-8.5'
* PHP-8.5:
  Add RUN_RESOURCE_HEAVY_TESTS env var
2026-02-27 15:05:28 +01:00
Ilija Tovilo 07e29acbd4 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Add RUN_RESOURCE_HEAVY_TESTS env var
2026-02-27 15:05:21 +01:00
Ilija Tovilo 6f91209260 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add RUN_RESOURCE_HEAVY_TESTS env var
2026-02-27 15:05:14 +01:00
Arnaud Le Blanc 65b4073922 Include the actual stub name in generated arginfo headers (#20993) 2026-01-21 20:57:00 +01:00
Niels Dossche d635c8788b xml: Fix deprecation properly by backporting the modern-but-actually-old implementation 2025-12-03 22:16:54 +01:00
Ilija Tovilo fe070fcc75 Fix yet another xml deprecation 2025-12-03 14:51:52 +01:00
Niels Dossche ca7f556002 xml: Use strlen() (#20544) 2025-11-20 21:54:38 +01:00
Niels Dossche 4a12745705 xml: Optimize attribute array construction (#20515)
Attributes can't be numeric strings by the definition of the grammar, so
don't bother with the symbol table stuff.
2025-11-18 18:49:13 +01:00
Niels Dossche 3e7672c227 Merge branch 'PHP-8.5'
* PHP-8.5:
  xml: Use safe_emalloc() correctly
2025-11-15 12:45:58 +01:00
Niels Dossche 0909f1305d Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  xml: Use safe_emalloc() correctly
2025-11-15 12:45:53 +01:00
Niels Dossche 835c6c7c7f Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  xml: Use safe_emalloc() correctly
2025-11-15 12:45:46 +01:00
Niels Dossche 48b19a8ede xml: Use safe_emalloc() correctly
Fortunately, libxml won't allow _at this point in time_ to have more
than INT_MAX/5 attributes, so this doesn't cause issues right now.
However, if this limit is ever raised then it can cause an integer
overflow which will cause a heap overflow.
So future-proof this code by properly using safe_emalloc().

Closes GH-20472.
2025-11-15 12:45:28 +01:00
Niels Dossche 0375060d16 xml: Don't make copies of the object, remove self-reference (#20471) 2025-11-15 01:02:11 +01:00
Niels Dossche 11070509ae xml: Drop unused XML_GetCurrentByteCount() compatibility wrapper (#20476) 2025-11-14 18:23:13 +01:00
Niels Dossche 94831808af xml: Drop unused version function (#20467) 2025-11-13 08:31:02 +01:00
Niels Dossche 7a96a680cc Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  xml: Fix unused variable warning
2025-11-11 23:03:19 +01:00
Niels Dossche c145c2018e xml: Fix unused variable warning 2025-11-11 23:03:12 +01:00
Niels Dossche af46c3f3c1 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback (#20453)
2025-11-11 22:49:04 +01:00
Niels Dossche f7c7948d00 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback (#20453)
2025-11-11 22:48:10 +01:00
Niels Dossche 0ad340fdcf Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback (#20453)
2025-11-11 22:47:54 +01:00
Niels Dossche 3cc36b0b5e Fix GH-20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback (#20453)
We would need to escape the attributes, but there's no builtin method
that we can call in libxml2 to do so in a way consistent with the
attribute escape rules and expat.
In fact, expat just repeats the input, while we reconstruct it.
To fix the issue, and fix consistency with expat, we repeat the input as
well. This works by seeking to the start and end of the tag and passing
it to the default handler. This is fine for the parser because the
parser used in ext/xml is always in non-progressive mode, so we have
access to the entire input buffer.
2025-11-11 22:47:15 +01:00
Niels Dossche 677c7fe31b xml: Migrate start_element_handler_ns to ZendMM 2025-10-11 23:49:30 +02:00
Niels Dossche e0561f0c8e xml: Migrate qualify_namespace to ZendMM 2025-10-11 23:49:30 +02:00
Niels Dossche 20cc3a35e5 xml: Migrate start_element_handler to ZendMM 2025-10-11 23:49:30 +02:00
Niels Dossche c9c904f816 xml: Migrate _ns_separator to ZendMM 2025-10-11 23:49:30 +02:00
Niels Dossche f63b011eee xml: Migrate build_entity to ZendMM 2025-10-11 23:49:30 +02:00
Niels Dossche 8e405ca22a xml: Migrate build_comment to ZendMM 2025-10-11 23:49:30 +02:00