641 Commits
Author SHA1 Message Date
David Carlier 05d164f306 Merge branch 'PHP-8.6'
* PHP-8.6:
  Fix GH-24488: GC double-frees the SimpleXMLElement properties table
2026-10-22 13:27:22 +01:00
David Carlier e4576ef7a4 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  Fix GH-24488: GC double-frees the SimpleXMLElement properties table
2026-10-22 13:27:21 +01:00
David Carlier 5bd92da0ab Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-24488: GC double-frees the SimpleXMLElement properties table
2026-10-22 13:27:20 +01:00
evanfordandClaude Opus 5.5 f963484725 Fix GH-24488: GC double-frees the SimpleXMLElement properties table
Since the GH-24050 fix, gc_collect_white() adds the table returned by
get_gc to the garbage buffer. sxe_object_free_storage() released
sxe->properties with zend_hash_release(), which does not remove the
table from the GC buffer, so the GC later read and freed it again.
Use zend_array_release(), which goes through zend_array_destroy().

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Close GH-24494
2026-10-22 13:24:35 +01:00
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
Ilia Alshanetsky 75204bee6f Fix GH-12171: resolve SimpleXML nodes before equality compare (#23187)
Property proxies like $xml->first store the parent node plus an element
iterator name. sxe_objects_compare compared the parent wrappers, so
sibling proxies always compared equal. Resolve each side through
php_sxe_get_first_node_non_destructive before comparing. When both sides
resolve to no node, keep comparing the parent wrappers, so two empty
results from the same parent still compare equal.

Fixes GH-12171
Closes GH-23187
2026-10-05 20:01:55 -04:00
Ilia Alshanetsky 475811a186 Merge branch 'PHP-8.5'
* PHP-8.5:
  simplexml: fix addChild() namespace filter on the returned element
2026-09-08 06:26:50 -04:00
Ilia Alshanetsky cf65d03d60 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  simplexml: fix addChild() namespace filter on the returned element
2026-09-08 06:25:33 -04:00
Ilia Alshanetsky 8b13fcc13e simplexml: fix addChild() namespace filter on the returned element
addChild() passed the caller's prefix to node_as_zval_str() with isprefix
set to 0, so the returned element filtered its children by comparing that
prefix against the namespace href and matched nothing. Take the prefix from
the created node and mark it as one, but only when the caller asked for a
namespace, so a plain addChild() keeps the unfiltered view that its
attributes and non-namespaced children rely on.

Closes GH-23599
2026-09-08 06:20:54 -04:00
Ilia Alshanetsky 860dda81f7 Merge branch 'PHP-8.5'
* PHP-8.5:
  [SimpleXML] Fix creating new attributes via attributes() dimension write
2026-08-30 11:05:13 -04:00
Ilia Alshanetsky 85417195b9 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  [SimpleXML] Fix creating new attributes via attributes() dimension write
2026-08-30 11:04:27 -04:00
Ilia Alshanetsky fc7a6b9007 [SimpleXML] Fix creating new attributes via attributes() dimension write
sxe_prop_dim_write() overwrote the element node with the first attribute
node when resolving an SXE_ITER_ATTRLIST iterator, so xmlNewProp() targeted
a non-element node and was skipped entirely when no attribute existed yet.
Keep the element node in place and resolve only the attribute list start,
so $x->attributes()["new"] = "v" creates the attribute like the symmetric
$x["new"] path; property writes on the attributes() object share the fixed
path while read/exists/unset handlers are unaffected by this defect.

Closes GH-23500
2026-08-30 11:03:49 -04:00
Ilia Alshanetsky 9d58ce53a1 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix segfault comparing uninitialized SimpleXMLElement instances
2026-08-10 10:23:54 -04:00
Ilia Alshanetsky 2806a3637e Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix segfault comparing uninitialized SimpleXMLElement instances
2026-08-10 10:23:26 -04:00
Ilia Alshanetsky 7b1f5637b6 Fix segfault comparing uninitialized SimpleXMLElement instances
sxe_objects_compare dereferenced document->ptr when both nodes were
NULL without checking document. A subclass that skips parent
__construct leaves document NULL, so $a == $b segfaulted. Compare the
documents only when both are set; anything else is uncomparable.

Closes GH-23067
2026-08-10 10:06:49 -04:00
Ilia Alshanetsky bda5a4943e Reject NUL bytes in the SimpleXMLElement constructor (#23069)
With dataIsURL set the first argument goes to xmlReadFile as a C string,
so new SimpleXMLElement("/tmp/ok.xml\0evil", 0, true) truncates at the NUL
and quietly loads /tmp/ok.xml. simplexml_load_file() and
SimpleXMLElement::asXML() already declare their path argument as a path;
the constructor took a plain string, so the check never ran.

Closes GH-23069
2026-08-09 19:44:01 -04:00
Ilia Alshanetsky 4e55e35ead Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix SimpleXML integer offsets that cannot resolve aliasing a node
2026-08-09 14:14:07 -04:00
Ilia Alshanetsky 4c955f4a2b Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix SimpleXML integer offsets that cannot resolve aliasing a node
2026-08-09 14:13:43 -04:00
Ilia Alshanetsky 9e696413e8 Fix SimpleXML integer offsets that cannot resolve aliasing a node
sxe_get_element_by_offset scanned with nodendx <= offset, so a negative
offset skipped the loop and returned the node it started from, and the
SXE_ITER_NONE branches of the read and write handlers aliased the node
for every offset other than 0. Reads and isset() reported an existing
element and writes overwrote it. An offset that resolves to no element
now warns and leaves the document alone.

Closes GH-23068
2026-08-09 14:02:10 -04: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 85d1394380 license-update: ext/simplexml source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Alexandre Daubois a8543dfdd2 Convert remaining zend_parse_parameters_none() to ZPP (#21343) 2026-03-16 09:28:08 +01:00
Niels Dossche 08ba240c81 simplexml: Avoid double lookups and unnecessary allocations in getNamespaces() (#20447) 2025-11-11 11:19:29 +01:00
Niels Dossche cff7d9eb6f Merge branch 'PHP-8.5'
* PHP-8.5:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
2025-10-12 11:25:46 +02:00
Niels Dossche 0b231c4895 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
2025-10-12 11:25:31 +02:00
Niels Dossche aa1585f110 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
2025-10-12 11:25:25 +02:00
Niels Dossche efa1fafc2f Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
If only we did not have the pseudo-key "@attributes", we could've just
removed the custom get_debug_info implementation and this would work out
of the box. Anyway, we just have to manually check for an override now.

Closes GH-20131.
2025-10-12 11:24:45 +02:00
Niels Dossche 890021e2be SimpleXML: Use RETURN_STRINGL_FAST() for key() (#20127)
We do the same for getName() because names are often one char.
2025-10-11 10:46:33 +02:00
Niels Dossche 4db8993ee2 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix NEWS order
  Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
2025-09-29 16:09:07 +02:00
Niels Dossche c1a6627417 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix NEWS order
  Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
2025-09-29 16:08:56 +02:00
Niels Dossche 1bda46eb83 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix NEWS order
  Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
2025-09-29 16:08:31 +02:00
Niels Dossche d94846c3b4 Fix GH-19988: zend_string_init with NULL pointer in simplexml (UB)
Normally, simplexml cannot import document nodes,
but xsl allows to circumvent this.
A document does not have a name, so we return the empty string
in that case.
While we could add an explicit check, we might as well switch
the macro to a form that would be more optimal anyway as many
tag names can be single characters.

The test was added in xsl because adding it in simplexml would
break out-of-tree builds of simplexml.

Closes GH-19990.
2025-09-29 16:07:34 +02:00
Tim Düsterhus 0583c66e2f simplexml: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Niels Dossche 542712099f Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix naming clash with libxml macro
2025-09-14 16:40:47 +02:00
Ruoyu Zhong 8774e96bd4 Fix naming clash with libxml macro
In the macOS 26 SDK, xmlFree is defined as a macro for free. This causes
issues where a same-named variable is used. Renaming the variable to
should_free resolves the issue.

See:

    $ grep -B4 -A2 -n "#define xmlFree(" "Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.sdk/usr/include/libxml/globals.h"
    261-#if defined(LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS)
    262-#define xmlMalloc(size) malloc(size)
    263-#define xmlMallocAtomic(size) malloc(size)
    264-#define xmlRealloc(ptr, size) realloc((ptr), (size))
    265:#define xmlFree(ptr) free(ptr)
    266-#define xmlMemStrdup(str) strdup(str)
    267-#endif

Fixes:
```
    In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/xmlIO.h:117,
                    from /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include/libxml/parser.h:813,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/php_dom.h:29,
                    from /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:26:
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c: In function 'dom_compare_value':
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:208:17: error: called object 'free' is not a function or function pointer
      208 |                 xmlFree(attr_value);
          |                 ^~~~~~~
    /private/tmp/php-20250914-13349-uqsk5o/php-8.4.12/ext/dom/attr.c:204:14: note: declared here
      204 |         bool free;
          |              ^~~~
    make: *** [ext/dom/attr.lo] Error 1
```

Closes GH-19832.

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-09-14 16:40:22 +02:00
Niels Dossche d2514e3969 Simplify SimpleXML code for checking if count() is overridden by a userland class (#18722) 2025-05-31 15:59:14 +02:00
Niels Dossche efaae93e48 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
2025-05-20 21:32:27 +02:00
Niels Dossche 40e667280b Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
xmlSave() also can flush in some cases. When the encoding is not
available this can fail for short inputs, resulting in an empty string
which is interned but then wrongly tagged by RETURN_NEW_STR.
Fix this by checking the error condition and switching to RETURN_STR for
defense-in-depth.

This issue also exists on 8.3, but does not crash; however, due to the
different API usage internally I cannot easily fix it on 8.3. There it
gives a partial output.

Closes GH-18606.
2025-05-20 21:32:17 +02:00
Niels Dossche 3ba725a556 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:42 +02:00
Niels Dossche a019fbd970 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:12 +02:00
Niels Dossche ba0853888d Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
For dynamic fetches the cache_slot will be NULL, so we have to check for
that when resetting the cache. For zip and xmlreader this couldn't
easily be tested because of a lack of writable properties.

Closes GH-18307.
2025-04-11 23:33:58 +02:00
Niels Dossche 86a67fef48 Fix GH-12231: SimpleXML xpath should warn when returning other return types than node lists
Closes GH-18073.
2025-03-17 19:37:59 +01:00
Niels Dossche d95b9d6d32 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:41:21 +01:00
Niels Dossche ee4a9a4a7c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:37:07 +01:00
Niels Dossche ce8ab5f16a Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00