402 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 65f7c719a3 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  ext/libxml: Keep SimpleXML children alive across reconstruction
2026-09-29 14:53:12 -04:00
Ilia Alshanetsky e926c2a2ec Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/libxml: Keep SimpleXML children alive across reconstruction
2026-09-29 14:16:24 -04:00
Ilia Alshanetsky efb8ad276d ext/libxml: Keep SimpleXML children alive across reconstruction
Reconstructing a SimpleXMLElement decremented the shared node and then
installed a new document while the old pointer was still set, so the
second decrement freed a node a child object still held. Clear the
pointer before the new node is installed.

Closes GH-23931
2026-09-29 14:06:21 -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
NickSdot d9640d76c4 ext/simplexml: applied fixers to improve test robustness (#23030) 2026-08-22 14:03:08 +01: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 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
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
Gina Peter Banyard 05eda4318d Add missing extension dependencies for tests 2025-09-11 15:10:49 +02:00
Gina Peter Banyard 1e0c8baf05 tree: drop non canonical casts and ZPP tests 2025-08-06 13:20:28 +01:00
Gina Peter Banyard 4baecc1d4a ext/simplexml: Remove bool type coercions in tests 2025-06-23 14:57:05 +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 fd7ebd4d15 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix sxe test
2025-04-11 23:57:03 +02:00
Niels Dossche 7415dc4649 Fix sxe test 2025-04-11 23:56:57 +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 09189026e6 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix test GH-16535 for libxml2 2.14
  Fix tests for libxml2 2.14
2025-03-10 20:23:43 +01:00
Niels Dossche 1befdce0e6 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix test GH-16535 for libxml2 2.14
  Fix tests for libxml2 2.14
2025-03-10 20:23:36 +01:00
Niels Dossche 239b01db7c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix tests for libxml2 2.14
2025-03-10 20:22:27 +01:00
Niels Dossche f209eb448e Fix tests for libxml2 2.14
See GH-18009.
2025-03-10 20:22:11 +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
Niels Dossche 3eb79e146f Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17409: Assertion failure Zend/zend_hash.c:1730
  NEWS
  Add comment
  Fix GH-16892: ini_parse_quantity() fails to parse inputs starting with 0x0b
  Fix GH-16886: ini_parse_quantity() fails to emit warning for 0x+0
  Merge duplicate code blocks
2025-01-09 19:54:46 +01:00
Niels Dossche a2a7287b87 Fix GH-17409: Assertion failure Zend/zend_hash.c:1730
The array merging function may still hold the properties array while the
object is already being destroyed. Therefore, we should take into
account the refcount in simplexml's destruction code.
It may be possible to trigger this in other ways too.

Closes GH-17421.
2025-01-09 19:53:54 +01:00
Niels Dossche 9eaee687d3 Revert 746b1cf4 "Access long value directly for call to count() in simplexml"
The count() function has a tentative return type.
Add a comment for the future.
2024-12-29 14:37:25 +01:00