Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7b8a61a
Zend/tests: merge `constant_expressions` into `constexpr`, update nam…
DanielEScherzer Feb 21, 2025
9beccce
Fix GH-17847: xinclude destroys live node
ndossche Feb 21, 2025
be3d128
Merge branch 'PHP-8.3' into PHP-8.4
ndossche Feb 21, 2025
8ce16d5
Merge branch 'PHP-8.4'
ndossche Feb 21, 2025
769f292
Fix GH-17879: readfile_variation8-win32.phpt test conflict
cmb69 Feb 21, 2025
2c911e4
Merge branch 'PHP-8.3' into PHP-8.4
cmb69 Feb 21, 2025
49d798a
Merge branch 'PHP-8.4'
cmb69 Feb 21, 2025
7974c62
Fix using Dom\Node with Dom\XPath callbacks
ndossche Feb 22, 2025
77b6a79
Merge branch 'PHP-8.4'
ndossche Feb 22, 2025
6181901
Zend/tests: organize some tests with sub directories (8) (#17873)
DanielEScherzer Feb 22, 2025
1eacd4a
Avoid unnecessary string refcounting in ext/dom (#17889)
ndossche Feb 22, 2025
03f97fc
Avoid unnecessary string refcounting in ext/pcre (#17893)
ndossche Feb 22, 2025
b1841fd
Avoid unnecessary string refcounting in ext/mbstring (#17892)
ndossche Feb 22, 2025
67a349d
ext/bz2: removing useless casts for filter ZendMM parts. (#17887)
devnexen Feb 23, 2025
cefdf00
Fix GH-17899: zend_test_compile_string crash on invalid script path.
devnexen Feb 23, 2025
e8dda54
Merge branch 'PHP-8.3' into PHP-8.4
devnexen Feb 23, 2025
f89b0a2
Merge branch 'PHP-8.4'
devnexen Feb 23, 2025
404c96e
Avoid string copies for date/time format in firebird (#17902)
ndossche Feb 23, 2025
2c251f9
[skip ci] zend_test adding closing tags to newer tests
devnexen Feb 23, 2025
96340e9
Merge branch 'PHP-8.3' into PHP-8.4
devnexen Feb 23, 2025
3881347
Merge branch 'PHP-8.4'
devnexen Feb 23, 2025
6746634
Zend/tests: organize some tests with sub directories (9) (#17897)
DanielEScherzer Feb 23, 2025
353f214
Fix cycle leak in sqlite3 setAuthorizer()
ndossche Feb 23, 2025
7603509
Merge branch 'PHP-8.3' into PHP-8.4
ndossche Feb 23, 2025
635fe26
Fix memory leaks in pdo_sqlite callback registration
ndossche Feb 23, 2025
6a4b0c9
Merge branch 'PHP-8.4'
ndossche Feb 23, 2025
065b4ec
ext/gd/tests: backport optional PNG support
orlitzky Aug 23, 2023
34d0e4f
Merge branch 'PHP-8.3' into PHP-8.4
devnexen Feb 23, 2025
a0e1ce1
Merge branch 'PHP-8.4'
devnexen Feb 23, 2025
1fa15ab
Remove pointless call to zval_ptr_dtor() in sqlite3 (#17906)
ndossche Feb 23, 2025
174a7fe
Fix GH-17891 gh17373.phpt test issue without freetype support
orlitzky Feb 24, 2025
fc73da5
Merge branch 'PHP-8.3' into PHP-8.4
devnexen Feb 24, 2025
0610122
Merge branch 'PHP-8.4'
devnexen Feb 24, 2025
53fa98e
Fix GH-17715: Handle preloaded internal function runtime cache (#17835)
bwoebi Feb 24, 2025
bcd7222
Merge branch 'PHP-8.4'
bwoebi Feb 24, 2025
e71b8ca
[skip ci] Use laravel default branch in community build
iluuu1994 Feb 24, 2025
09d7f69
Merge branch 'PHP-8.1' into PHP-8.2
iluuu1994 Feb 24, 2025
a93ad36
Merge branch 'PHP-8.2' into PHP-8.3
iluuu1994 Feb 24, 2025
ca75ebf
Merge branch 'PHP-8.3' into PHP-8.4
iluuu1994 Feb 24, 2025
0008a1e
Merge branch 'PHP-8.4'
iluuu1994 Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ jobs:
- name: Test Laravel
if: ${{ !cancelled() }}
run: |
git clone https://github.com/laravel/framework.git --branch=master --depth=1
git clone https://github.com/laravel/framework.git --depth=1
cd framework
git rev-parse HEAD
php /usr/bin/composer install --no-progress --ignore-platform-reqs
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Zend/tests/constexpr/new_dynamic_class_name.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Dynamic class name in new is not supported
Dynamic class name in new is supported
--FILE--
<?php

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/constexpr/new_invalid_operation_in_arg.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Invalid operation in new arg in const expr
Valid operation in new arg in const expr
--FILE--
<?php

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/constexpr/new_static.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Static in new is not supported
Static in new is supported
--FILE--
<?php

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion Zend/zend_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ static void zend_enum_register_func(zend_class_entry *ce, zend_known_string_id n
zif->module = EG(current_module);
zif->scope = ce;
zif->T = ZEND_OBSERVER_ENABLED;
if (EG(active)) { // at run-time
if (EG(active)) { // at run-time
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
zif->fn_flags |= ZEND_ACC_PRELOADED;
}
ZEND_MAP_PTR_INIT(zif->run_time_cache, zend_arena_calloc(&CG(arena), 1, zend_internal_run_time_cache_reserved_size()));
} else {
#ifdef ZTS
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_map_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ typedef struct _zend_string zend_string;
} while (0)
# define ZEND_MAP_PTR_BIASED_BASE(real_base) \
((void*)(((uintptr_t)(real_base)) + zend_map_ptr_static_size * sizeof(void *) - 1))
/* Note: chunked like: [8192..12287][4096..8191][0..4095] */
#define ZEND_MAP_PTR_STATIC_NUM_TO_PTR(num) \
((void **)CG(map_ptr_real_base) + zend_map_ptr_static_size - ZEND_MM_ALIGNED_SIZE_EX((num) + 1, 4096) + ((num) & 4095))
#else
# error "Unknown ZEND_MAP_PTR_KIND"
#endif
Expand Down
4 changes: 2 additions & 2 deletions ext/bz2/bz2_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ typedef struct _php_bz2_filter_data {

static void *php_bz2_alloc(void *opaque, int items, int size)
{
return (void *)safe_pemalloc(items, size, 0, ((php_bz2_filter_data*)opaque)->persistent);
return safe_pemalloc(items, size, 0, ((php_bz2_filter_data*)opaque)->persistent);
}

static void php_bz2_free(void *opaque, void *address)
{
pefree((void *)address, ((php_bz2_filter_data*)opaque)->persistent);
pefree(address, ((php_bz2_filter_data*)opaque)->persistent);
}
/* }}} */

Expand Down
75 changes: 11 additions & 64 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,12 @@ zend_result dom_document_version_write(dom_object *obj, zval *newval)
{
DOM_PROP_NODE(xmlDocPtr, docp, obj);

/* Cannot fail because the type is either null or a string. */
zend_string *str = zval_get_string(newval);
/* Type is ?string */
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);

if (php_dom_follow_spec_intern(obj)) {
if (!zend_string_equals_literal(str, "1.0") && !zend_string_equals_literal(str, "1.1")) {
zend_value_error("Invalid XML version");
zend_string_release_ex(str, 0);
return FAILURE;
}
}
Expand All @@ -211,7 +210,6 @@ zend_result dom_document_version_write(dom_object *obj, zval *newval)

docp->version = xmlStrdup((const xmlChar *) ZSTR_VAL(str));

zend_string_release_ex(str, 0);
return SUCCESS;
}

Expand Down Expand Up @@ -394,16 +392,15 @@ zend_result dom_document_document_uri_write(dom_object *obj, zval *newval)
{
DOM_PROP_NODE(xmlDocPtr, docp, obj);

/* Cannot fail because the type is either null or a string. */
zend_string *str = zval_get_string(newval);
/* Type is ?string */
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);

if (docp->URL != NULL) {
xmlFree(BAD_CAST docp->URL);
}

docp->URL = xmlStrdup((const xmlChar *) ZSTR_VAL(str));

zend_string_release_ex(str, 0);
return SUCCESS;
}

Expand Down Expand Up @@ -1668,47 +1665,6 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
}
/* }}} end dom_document_savexml */

static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur) /* {{{ */
{
xmlNodePtr xincnode;

xincnode = cur;
cur = cur->next;
xmlUnlinkNode(xincnode);
php_libxml_node_free_resource(xincnode);

return cur;
}
/* }}} */

static void php_dom_remove_xinclude_nodes(xmlNodePtr cur) /* {{{ */
{
while(cur) {
if (cur->type == XML_XINCLUDE_START) {
cur = php_dom_free_xinclude_node(cur);

/* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
while(cur && cur->type != XML_XINCLUDE_END) {
/* remove xinclude processing nodes from recursive xincludes */
if (cur->type == XML_ELEMENT_NODE) {
php_dom_remove_xinclude_nodes(cur->children);
}
cur = cur->next;
}

if (cur && cur->type == XML_XINCLUDE_END) {
cur = php_dom_free_xinclude_node(cur);
}
} else {
if (cur->type == XML_ELEMENT_NODE) {
php_dom_remove_xinclude_nodes(cur->children);
}
cur = cur->next;
}
}
}
/* }}} */

static void dom_xinclude_strip_references(xmlNodePtr basep)
{
php_libxml_node_free_resource(basep);
Expand All @@ -1721,17 +1677,19 @@ static void dom_xinclude_strip_references(xmlNodePtr basep)
}
}

/* See GH-14702.
* We have to remove userland references to xinclude fallback nodes because libxml2 will make clones of these
/* See GH-14702 and GH-17847.
* We have to remove userland references to xinclude nodes because libxml2 will make clones of these
* and remove the original nodes. If the originals are removed while there are still userland references
* this will cause memory corruption. */
static void dom_xinclude_strip_fallback_references(const xmlNode *basep)
{
xmlNodePtr current = basep->children;

/* TODO: try to improve loop search performance */
while (current) {
if (current->type == XML_ELEMENT_NODE && current->ns != NULL && current->_private != NULL
&& xmlStrEqual(current->name, XINCLUDE_FALLBACK)
if (current->type == XML_ELEMENT_NODE
&& current->ns != NULL
&& xmlStrEqual(current->name, XINCLUDE_NODE)
&& (xmlStrEqual(current->ns->href, XINCLUDE_NS) || xmlStrEqual(current->ns->href, XINCLUDE_OLD_NS))) {
dom_xinclude_strip_references(current);
}
Expand All @@ -1744,22 +1702,11 @@ static int dom_perform_xinclude(xmlDocPtr docp, dom_object *intern, zend_long fl
{
dom_xinclude_strip_fallback_references((const xmlNode *) docp);

flags |= XML_PARSE_NOXINCNODE;
PHP_LIBXML_SANITIZE_GLOBALS(xinclude);
int err = xmlXIncludeProcessFlags(docp, (int)flags);
PHP_LIBXML_RESTORE_GLOBALS(xinclude);

/* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
but are not wanted in resulting document - must be done even if err as it could fail after
having processed some xincludes */
xmlNodePtr root = docp->children;
while (root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) {
root = root->next;
}
if (root) {
php_dom_remove_xinclude_nodes(root);
}

php_libxml_invalidate_node_list_cache(intern->document);

return err;
Expand Down
5 changes: 2 additions & 3 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ zend_result dom_node_node_value_write(dom_object *obj, zval *newval)
{
DOM_PROP_NODE(xmlNodePtr, nodep, obj);

/* Cannot fail because the type is either null or a string. */
zend_string *str = zval_get_string(newval);
/* Type is ?string */
zend_string *str = Z_TYPE_P(newval) == IS_NULL ? ZSTR_EMPTY_ALLOC() : Z_STR_P(newval);

/* Access to Element node is implemented as a convenience method */
switch (nodep->type) {
Expand All @@ -213,7 +213,6 @@ zend_result dom_node_node_value_write(dom_object *obj, zval *newval)

php_libxml_invalidate_node_list_cache(obj->document);

zend_string_release_ex(str, 0);
return SUCCESS;
}

Expand Down
41 changes: 41 additions & 0 deletions ext/dom/tests/gh17847.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
GH-17847 (xinclude destroys live node)
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML(<<<XML
<root>
<xi:include href="thisisnonexistent" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:fallback>fallback<p>garbage</p></xi:fallback>
<p>garbage</p>
</xi:include>
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="thisisnonexistent">
<p>garbage</p>
</xi:include>
</xi:test>
</root>
XML);

$xpath = new DOMXPath($doc);

$garbage = [];
foreach ($xpath->query('//p') as $entry)
$garbage[] = $entry;

@$doc->xinclude();

foreach ($garbage as $node) {
try {
var_dump($node->localName);
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
Invalid State Error
Invalid State Error
Invalid State Error
17 changes: 17 additions & 0 deletions ext/dom/tests/modern/xml/return_dom_node_from_xpath.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Returning a Dom\Node from Dom\XPath callback
--EXTENSIONS--
dom
--FILE--
<?php

$dom = Dom\XMLDocument::createFromString('<root/>');
$xpath = new Dom\XPath($dom);
$xpath->registerPhpFunctionNs('urn:x', 'test', fn() => $dom->createElement('foo'));
$xpath->registerNamespace('x', 'urn:x');
$test = $xpath->query('x:test()');
var_dump($test[0]->nodeName);

?>
--EXPECT--
string(3) "foo"
16 changes: 10 additions & 6 deletions ext/dom/xpath_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#if defined(HAVE_LIBXML) && defined(HAVE_DOM)

#include "php_dom.h"
#include "internal_helpers.h"
#include <libxml/parserInternals.h>

static void xpath_callbacks_entry_dtor(zval *zv)
Expand Down Expand Up @@ -205,13 +206,14 @@ static zend_result php_dom_xpath_callback_ns_update_method_handler(
ZVAL_PTR(&registered_value, fcc);

if (!key) {
zend_string *str = zval_try_get_string(entry);
zend_string *tmp_str;
zend_string *str = zval_try_get_tmp_string(entry, &tmp_str);
if (str && php_dom_xpath_is_callback_name_valid_and_throw(str, name_validation, true)) {
zend_hash_update(&ns->functions, str, &registered_value);
if (register_func) {
register_func(ctxt, namespace, str);
}
zend_string_release_ex(str, false);
zend_tmp_string_release(tmp_str);
} else {
zend_fcc_dtor(fcc);
efree(fcc);
Expand Down Expand Up @@ -425,7 +427,8 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
}

if (Z_TYPE(callback_retval) != IS_UNDEF) {
if (Z_TYPE(callback_retval) == IS_OBJECT && instanceof_function(Z_OBJCE(callback_retval), dom_node_class_entry)) {
if (Z_TYPE(callback_retval) == IS_OBJECT
&& (instanceof_function(Z_OBJCE(callback_retval), dom_get_node_ce(php_dom_follow_spec_node((const xmlNode *) ctxt->context->doc))))) {
xmlNode *nodep;
dom_object *obj;
if (xpath_callbacks->node_list == NULL) {
Expand All @@ -439,13 +442,14 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
} else if (Z_TYPE(callback_retval) == IS_FALSE || Z_TYPE(callback_retval) == IS_TRUE) {
valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(callback_retval) == IS_TRUE));
} else if (Z_TYPE(callback_retval) == IS_OBJECT) {
zend_type_error("Only objects that are instances of DOMNode can be converted to an XPath expression");
zend_type_error("Only objects that are instances of DOM nodes can be converted to an XPath expression");
zval_ptr_dtor(&callback_retval);
return FAILURE;
} else {
zend_string *str = zval_get_string(&callback_retval);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(&callback_retval, &tmp_str);
valuePush(ctxt, xmlXPathNewString(BAD_CAST ZSTR_VAL(str)));
zend_string_release_ex(str, 0);
zend_tmp_string_release(tmp_str);
}
zval_ptr_dtor(&callback_retval);
}
Expand Down
4 changes: 4 additions & 0 deletions ext/gd/tests/gh17373.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Bug GH-17373 (imagefttext() ignores clipping rect for palette images)
--EXTENSIONS--
gd
--SKIPIF--
<?php
if(!function_exists('imagefttext')) die('skip imagefttext() not available');
?>
--FILE--
<?php
$im = imagecreate(64, 32);
Expand Down
7 changes: 4 additions & 3 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ static zend_result php_mb_parse_encoding_array(HashTable *target_hash, const mbf
size_t n = 0;
zval *hash_entry;
ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
zend_string *encoding_str = zval_try_get_string(hash_entry);
zend_string *tmp_encoding_str;
zend_string *encoding_str = zval_try_get_tmp_string(hash_entry, &tmp_encoding_str);
if (UNEXPECTED(!encoding_str)) {
efree(ZEND_VOIDP(list));
return FAILURE;
Expand All @@ -415,12 +416,12 @@ static zend_result php_mb_parse_encoding_array(HashTable *target_hash, const mbf
n++;
} else {
zend_argument_value_error(arg_num, "contains invalid encoding \"%s\"", ZSTR_VAL(encoding_str));
zend_string_release(encoding_str);
zend_tmp_string_release(tmp_encoding_str);
efree(ZEND_VOIDP(list));
return FAILURE;
}
}
zend_string_release(encoding_str);
zend_tmp_string_release(tmp_encoding_str);
} ZEND_HASH_FOREACH_END();
*return_list = list;
*return_size = n;
Expand Down
Loading