Skip to content

Commit 6ae74eb

Browse files
authored
Merge branch 'php:master' into feature/portable-opcache
2 parents 1444e14 + 4d9fc50 commit 6ae74eb

29 files changed

+264
-204
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0alpha2
44

5+
- Core:
6+
. Fix OSS-Fuzz #427814452 (pipe compilation fails with assert).
7+
(nielsdos, ilutov)
8+
59
- DOM:
610
. Make cloning DOM node lists, maps, and collections fail. (nielsdos)
711

@@ -79,6 +83,8 @@ PHP NEWS
7983
(DanielEScherzer)
8084
. Do not use RTLD_DEEPBIND if dlmopen is available. (Daniil Gentili)
8185
. Make `clone()` a function. (timwolla, edorian)
86+
. Fixed bug GH-19081 (Wrong lineno in property error with constructor property
87+
promotion). (ilutov)
8288

8389
- Curl:
8490
. Added curl_multi_get_handles(). (timwolla)

Zend/Optimizer/zend_func_infos.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ static const func_info_t func_infos[] = {
131131
F1("imagecreatefromgd", MAY_BE_OBJECT|MAY_BE_FALSE),
132132
F1("imagecreatefromgd2", MAY_BE_OBJECT|MAY_BE_FALSE),
133133
F1("imagecreatefromgd2part", MAY_BE_OBJECT|MAY_BE_FALSE),
134-
#if defined(HAVE_GD_BMP)
135134
F1("imagecreatefrombmp", MAY_BE_OBJECT|MAY_BE_FALSE),
136-
#endif
137135
F1("imagecolorsforindex", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG),
138136
F1("imagegetclip", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG),
139137
#if defined(HAVE_GD_FREETYPE)

Zend/tests/ctor_promotion/ctor_promotion_callable_type.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Type of promoted property may not be callable
44
<?php
55

66
class Test {
7-
public function __construct(public callable $callable) {}
7+
public function __construct(
8+
public callable $callable
9+
) {}
810
}
911

1012
?>
1113
--EXPECTF--
12-
Fatal error: Property Test::$callable cannot have type callable in %s on line %d
14+
Fatal error: Property Test::$callable cannot have type callable in %s on line 5
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-18965: ASSERT_CHECK avoids pipe lhs free
3+
--INI--
4+
zend.assertions=0
5+
--FILE--
6+
<?php
7+
namespace Foo;
8+
range(0, 10) |> assert(...);
9+
echo "No leak\n";
10+
?>
11+
--EXPECT--
12+
No leak
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
OSS-Fuzz #427814452
3+
--FILE--
4+
<?php
5+
6+
try {
7+
false |> assert(...);
8+
} catch (\AssertionError $e) {
9+
echo $e::class, ": '", $e->getMessage(), "'\n";
10+
}
11+
try {
12+
0 |> "assert"(...);
13+
} catch (\AssertionError $e) {
14+
echo $e::class, ": '", $e->getMessage(), "'\n";
15+
}
16+
try {
17+
false |> ("a"."ssert")(...);
18+
} catch (\AssertionError $e) {
19+
echo $e::class, ": '", $e->getMessage(), "'\n";
20+
}
21+
22+
?>
23+
--EXPECT--
24+
AssertionError: ''
25+
AssertionError: ''
26+
AssertionError: ''

Zend/zend_compile.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6426,6 +6426,20 @@ static bool can_match_use_jumptable(zend_ast_list *arms) {
64266426
return 1;
64276427
}
64286428

6429+
static bool zend_is_pipe_optimizable_callable_name(zend_ast *ast)
6430+
{
6431+
if (ast->kind == ZEND_AST_ZVAL && Z_TYPE_P(zend_ast_get_zval(ast)) == IS_STRING) {
6432+
/* Assert compilation adds a message operand, but this is incompatible with the
6433+
* pipe optimization that uses a temporary znode for the reference elimination.
6434+
* Therefore, disable the optimization for assert.
6435+
* Note that "assert" as a name is always treated as fully qualified. */
6436+
zend_string *str = zend_ast_get_str(ast);
6437+
return !zend_string_equals_literal_ci(str, "assert");
6438+
}
6439+
6440+
return true;
6441+
}
6442+
64296443
static void zend_compile_pipe(znode *result, zend_ast *ast)
64306444
{
64316445
zend_ast *operand_ast = ast->child[0];
@@ -6453,7 +6467,8 @@ static void zend_compile_pipe(znode *result, zend_ast *ast)
64536467

64546468
/* Turn $foo |> bar(...) into bar($foo). */
64556469
if (callable_ast->kind == ZEND_AST_CALL
6456-
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
6470+
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT
6471+
&& zend_is_pipe_optimizable_callable_name(callable_ast->child[0])) {
64576472
fcall_ast = zend_ast_create(ZEND_AST_CALL,
64586473
callable_ast->child[0], arg_list_ast);
64596474
/* Turn $foo |> bar::baz(...) into bar::baz($foo). */
@@ -7683,6 +7698,8 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
76837698
uint32_t property_flags = param_ast->attr & (ZEND_ACC_PPP_MASK | ZEND_ACC_PPP_SET_MASK | ZEND_ACC_READONLY | ZEND_ACC_FINAL);
76847699
bool is_promoted = property_flags || hooks_ast;
76857700

7701+
CG(zend_lineno) = param_ast->lineno;
7702+
76867703
znode var_node, default_node;
76877704
uint8_t opcode;
76887705
zend_op *opline;

Zend/zend_language_scanner.l

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,7 @@ static zend_result zend_scan_escape_string(zval *zendlval, char *str, int len, c
921921
ZVAL_EMPTY_STRING(zendlval);
922922
} else {
923923
zend_uchar c = (zend_uchar)*str;
924-
if (c == '\n' || c == '\r') {
925-
CG(zend_lineno)++;
926-
}
924+
HANDLE_NEWLINE(c);
927925
ZVAL_INTERNED_STR(zendlval, ZSTR_CHAR(c));
928926
}
929927
goto skip_escape_conversion;
@@ -2512,9 +2510,7 @@ inline_char_handler:
25122510
ZVAL_EMPTY_STRING(zendlval);
25132511
} else {
25142512
zend_uchar c = (zend_uchar)*(yytext+bprefix+1);
2515-
if (c == '\n' || c == '\r') {
2516-
CG(zend_lineno)++;
2517-
}
2513+
HANDLE_NEWLINE(c);
25182514
ZVAL_INTERNED_STR(zendlval, ZSTR_CHAR(c));
25192515
}
25202516
goto skip_escape_conversion;

ext/dom/html_collection.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,47 +46,35 @@ static dom_named_item dom_html_collection_named_item(zend_string *key, zend_obje
4646

4747
/* 2. Return the first element in the collection for which at least one of the following is true: */
4848
xmlNodePtr basep = dom_object_get_node(objmap->baseobj);
49-
if (basep != NULL) {
50-
zend_long cur = 0;
51-
zend_long next = cur; /* not +1, otherwise we skip the first candidate */
52-
xmlNodePtr candidate = basep->children;
53-
bool iterate_tag_name = objmap->handler == &php_dom_obj_map_by_tag_name;
54-
while (candidate != NULL) {
55-
if (iterate_tag_name) {
56-
candidate = dom_get_elements_by_tag_name_ns_raw(basep, candidate, objmap->ns, objmap->local, objmap->local_lower, &cur, next);
57-
if (candidate == NULL) {
58-
break;
59-
}
60-
next = cur + 1;
61-
} else {
62-
if (candidate->type != XML_ELEMENT_NODE) {
63-
candidate = candidate->next;
64-
continue;
65-
}
49+
if (basep != NULL && basep->children != NULL) {
50+
php_dom_obj_map_collection_iter iter = {0};
51+
iter.candidate = basep->children;
52+
iter.basep = basep;
53+
54+
while (true) {
55+
objmap->handler->collection_named_item_iter(objmap, &iter);
56+
if (iter.candidate == NULL) {
57+
break;
6658
}
6759

68-
ZEND_ASSERT(candidate->type == XML_ELEMENT_NODE);
60+
ZEND_ASSERT(iter.candidate->type == XML_ELEMENT_NODE);
6961

7062
xmlAttrPtr attr;
7163

7264
/* it has an ID which is key; */
73-
if ((attr = xmlHasNsProp(candidate, BAD_CAST "id", NULL)) != NULL && dom_compare_value(attr, BAD_CAST ZSTR_VAL(key))) {
65+
if ((attr = xmlHasNsProp(iter.candidate, BAD_CAST "id", NULL)) != NULL && dom_compare_value(attr, BAD_CAST ZSTR_VAL(key))) {
7466
ret.context_intern = objmap->baseobj;
75-
ret.node = candidate;
67+
ret.node = iter.candidate;
7668
return ret;
7769
}
7870
/* it is in the HTML namespace and has a name attribute whose value is key; */
79-
else if (php_dom_ns_is_fast(candidate, php_dom_ns_is_html_magic_token)) {
80-
if ((attr = xmlHasNsProp(candidate, BAD_CAST "name", NULL)) != NULL && dom_compare_value(attr, BAD_CAST ZSTR_VAL(key))) {
71+
else if (php_dom_ns_is_fast(iter.candidate, php_dom_ns_is_html_magic_token)) {
72+
if ((attr = xmlHasNsProp(iter.candidate, BAD_CAST "name", NULL)) != NULL && dom_compare_value(attr, BAD_CAST ZSTR_VAL(key))) {
8173
ret.context_intern = objmap->baseobj;
82-
ret.node = candidate;
74+
ret.node = iter.candidate;
8375
return ret;
8476
}
8577
}
86-
87-
if (!iterate_tag_name) {
88-
candidate = candidate->next;
89-
}
9078
}
9179
}
9280

ext/dom/namednodemap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PHP_METHOD(DOMNamedNodeMap, getNamedItem)
6363
}
6464

6565
dom_nnodemap_object *objmap = Z_DOMOBJ_P(ZEND_THIS)->ptr;
66-
php_dom_obj_map_get_named_item_into_zval(objmap, named, NULL, return_value);
66+
php_dom_obj_map_get_ns_named_item_into_zval(objmap, named, NULL, return_value);
6767
}
6868
/* }}} end dom_namednodemap_get_named_item */
6969

@@ -108,7 +108,7 @@ PHP_METHOD(DOMNamedNodeMap, getNamedItemNS)
108108
objmap = (dom_nnodemap_object *)intern->ptr;
109109

110110
if (objmap != NULL) {
111-
php_dom_obj_map_get_named_item_into_zval(objmap, named, uri, return_value);
111+
php_dom_obj_map_get_ns_named_item_into_zval(objmap, named, uri, return_value);
112112
}
113113
}
114114
/* }}} end dom_namednodemap_get_named_item_ns */

0 commit comments

Comments
 (0)