Skip to content

Commit a9eddae

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17866: zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4
2 parents 229c1eb + 2542357 commit a9eddae

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-17866 (zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
#[Deprecated("xyzzy")]
8+
public function __invoke() {
9+
echo "In __invoke\n";
10+
}
11+
}
12+
13+
$foo = new Foo;
14+
$closure = Closure::fromCallable($foo);
15+
$test = $closure->__invoke(...);
16+
17+
$rc = new ReflectionMethod($test, '__invoke');
18+
var_dump($rc->getAttributes());
19+
var_dump($rc->isDeprecated());
20+
21+
$test();
22+
23+
?>
24+
--EXPECTF--
25+
array(1) {
26+
[0]=>
27+
object(ReflectionAttribute)#%d (1) {
28+
["name"]=>
29+
string(10) "Deprecated"
30+
}
31+
}
32+
bool(true)
33+
34+
Deprecated: Method Foo::__invoke() is deprecated, xyzzy in %s on line %d
35+
In __invoke

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* {
469469
zend_closure *closure = (zend_closure *)object;
470470
zend_function *invoke = (zend_function*)emalloc(sizeof(zend_function));
471471
const uint32_t keep_flags =
472-
ZEND_ACC_RETURN_REFERENCE | ZEND_ACC_VARIADIC | ZEND_ACC_HAS_RETURN_TYPE;
472+
ZEND_ACC_RETURN_REFERENCE | ZEND_ACC_VARIADIC | ZEND_ACC_HAS_RETURN_TYPE | ZEND_ACC_DEPRECATED;
473473

474474
invoke->common = closure->func.common;
475475
/* We return ZEND_INTERNAL_FUNCTION, but arg_info representation is the

Zend/zend_object_handlers.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,12 +1618,8 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
16181618
| ZEND_ACC_PUBLIC
16191619
| ZEND_ACC_VARIADIC
16201620
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED));
1621-
if (fbc->common.attributes) {
1622-
func->attributes = fbc->common.attributes;
1623-
GC_TRY_ADDREF(func->attributes);
1624-
} else {
1625-
func->attributes = NULL;
1626-
}
1621+
/* Attributes outlive the trampoline because they are created by the compiler. */
1622+
func->attributes = fbc->common.attributes;
16271623
if (is_static) {
16281624
func->fn_flags |= ZEND_ACC_STATIC;
16291625
}

Zend/zend_object_handlers.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,6 @@ ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_p
341341
} while (0)
342342

343343
#define zend_free_trampoline(func) do { \
344-
if ((func)->common.attributes) { \
345-
zend_array_release((func)->common.attributes); \
346-
} \
347344
if ((func) == &EG(trampoline)) { \
348345
EG(trampoline).common.attributes = NULL; \
349346
EG(trampoline).common.function_name = NULL; \

0 commit comments

Comments
 (0)