Commit graph

585 commits

Author SHA1 Message Date
Niels Dossche
84fae4a160 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (<= PHP 8.3)
  Fix bug #55098: SimpleXML iteration produces infinite loop
2023-09-20 20:58:08 +02:00
Niels Dossche
1a4e401bf0 Fix bug #55098: SimpleXML iteration produces infinite loop
Closes GH-12247.
2023-09-20 20:54:53 +02:00
Niels Dossche
7f0705b1fa Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
2023-09-17 16:35:39 +02:00
Niels Dossche
673babed24 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
2023-09-17 16:35:11 +02:00
Niels Dossche
f4f34b6e5a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
2023-09-17 16:34:38 +02:00
Niels Dossche
486276f0f9 Fix GH-12208: SimpleXML infinite loop when a cast is used inside a foreach
Closes GH-12229.
2023-09-17 16:33:32 +02:00
Niels Dossche
8f9626c0f7 Simplify php_sxe_count_elements_helper() by using non-destructive iterator reset 2023-09-17 16:21:54 +02:00
Niels Dossche
550ec29821 Use php_sxe_reset_iterator_no_clear_iter_data() to avoid having to store and restore iterator data
This makes the code less error-prone, and also makes it simpler.
2023-09-17 16:21:54 +02:00
Niels Dossche
695ec3c97e
Remove unnecessary _IS_BOOL case (#12230)
This can never be executed because booleans are handled in a special
case at the top of sxe_object_cast_ex().
2023-09-17 16:19:22 +02:00
Niels Dossche
fad0e4f4e7 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12223: Entity reference produces infinite loop in var_dump/print_r
  Fix GH-12192: SimpleXML infinite loop when getName() is called within foreach
  Fix GH-12186: segfault copying/cloning a finalized HashContext
2023-09-16 21:28:59 +02:00
Niels Dossche
4bb27e2d9b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12223: Entity reference produces infinite loop in var_dump/print_r
  Fix GH-12192: SimpleXML infinite loop when getName() is called within foreach
  Fix GH-12186: segfault copying/cloning a finalized HashContext
2023-09-16 21:28:24 +02:00
Niels Dossche
5df473d2c7 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12223: Entity reference produces infinite loop in var_dump/print_r
  Fix GH-12192: SimpleXML infinite loop when getName() is called within foreach
  Fix GH-12186: segfault copying/cloning a finalized HashContext
2023-09-16 21:24:20 +02:00
Niels Dossche
39a9e561f9 Fix GH-12223: Entity reference produces infinite loop in var_dump/print_r
Closes GH-12223.
2023-09-16 21:19:58 +02:00
Niels Dossche
4d888cf53f Fix GH-12192: SimpleXML infinite loop when getName() is called within foreach
This happens because getName() resets the iterator to the start because
it overwrites the iterator data.
We add a version of get_first_node that does not overwrite the iterator
data.

Closes GH-12193.
2023-09-16 21:19:28 +02:00
Niels Dossche
0fee720173 Simplify node check in simplexml 2023-09-16 14:02:48 +02:00
Niels Dossche
e5252a3f4d Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12170: Can't use xpath with comments in SimpleXML
2023-09-14 18:45:01 +02:00
Niels Dossche
60b1673b20 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12170: Can't use xpath with comments in SimpleXML
2023-09-14 18:44:39 +02:00
Niels Dossche
b3bce2328f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12170: Can't use xpath with comments in SimpleXML
2023-09-14 18:42:47 +02:00
Niels Dossche
747335f100 Fix GH-12170: Can't use xpath with comments in SimpleXML
Closes GH-12177.
2023-09-14 18:42:16 +02:00
Niels Dossche
05c46b71d4
Small optimization in php_sxe_get_first_node() by avoiding unwrapping iterator data (#12194) 2023-09-13 22:47:09 +02:00
Niels Dossche
6b54811547 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix #52751: XPath processing-instruction() function is not supported.
2023-09-11 00:15:32 +02:00
Niels Dossche
2440af0f97 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix #52751: XPath processing-instruction() function is not supported.
2023-09-11 00:13:25 +02:00
Niels Dossche
d1ef22585f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix #52751: XPath processing-instruction() function is not supported.
2023-09-11 00:12:16 +02:00
Niels Dossche
107443b311 Fix #52751: XPath processing-instruction() function is not supported.
Closes GH-12165.
2023-09-11 00:08:29 +02:00
Niels Dossche
bec1552a06
Remove useless SKIP_TEXT() invokes (#12164)
In the places I removed them, they were useless because there is already
a type check for a single node type, so I found it confusing having them
there.
2023-09-10 00:02:17 +02:00
Niels Dossche
d18bab5562 Preallocate result array size in simplexml xpath
This is the simplexml version of 4dea42a.
2023-09-09 22:59:24 +02:00
Niels Dossche
0ea268b51a Remove obsolete libxml2 code
LIBXML2_NEW_BUFFER is always defined since libxml2 2.9.0.
That's the minimum version PHP requires, so it will always be defined.
2023-09-09 21:58:13 +02:00
Ilija Tovilo
efc73f24c3
Revert "Call cast_object handler from get_properties_for"
This reverts commit 4182813ebf.
2023-08-07 12:58:12 +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
Ilija Tovilo
4182813ebf
Call cast_object handler from get_properties_for
Fixes GH-11547
Closes GH-11583
2023-07-25 17:59:44 +02:00
Vuudi
dda42be9d3
[skip ci] Fixed comment for SimpleXml function getName (#11537)
Co-authored-by: David Huang <david.huang@check24.de>
2023-06-26 13:50:29 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
ed097e30f0 No need for the double name pointer 2023-06-04 14:11:41 +01:00
Niels Dossche
47c277bde5 Use xmlStrEqual() instead of !xmlStrCmp()
This actually shows the intent clearer, and also from the docs of
xmlStrEqual:
"Should be a bit more readable and faster than xmlStrcmp()".
2023-06-04 14:11:41 +01:00
Niels Dossche
795127942b Remove double class entry variable 2023-06-04 14:11:41 +01:00
Niels Dossche
c6bffff96b Remove dead code from sxe_get_element_by_name()
retnode will never be set to anything other than NULL, because the
branch is always taken if the names match.
2023-06-04 14:11:41 +01: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
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Ilija Tovilo
3b92a96610
Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
Remi Collet
a48bf8a0b9
Merge branch 'PHP-8.0'
* PHP-8.0:
  NEWS
  Fix bug #81325  Segfault in zif_simplexml_import_dom
2021-08-03 12:08:03 +02:00
Remi Collet
112527d677
Fix bug #81325 Segfault in zif_simplexml_import_dom 2021-08-03 12:06:36 +02:00
Nikita Popov
6d505d4445 Add RETURN/RETVAL_COPY_DEREF() macros
These were missing from the set...

I think quite a few of these usages don't actually need the DEREF,
but I've just kept things as is for now.
2021-07-22 09:44:19 +02:00
Joe Watkins
570d9b63e9
Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Nikita Popov
cde735e630 Remove SimpleXMLElement dtor_obj handler
I don't see any reason why this cleanup needs to happen inside
dtor_obj.

If there is a reason, it's lacking in test coverage...
2021-06-09 11:46:28 +02:00