Skip to content

Commit 4833362

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #81430: Attribute instantiation leaves dangling pointer
2 parents 2b07513 + 2f6a06c commit 4833362

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

NEWS

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

5+
- Core:
6+
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
7+
(beberlei)
8+
59
- FPM:
610
. Fixed memory leak on invalid port. (David Carlier)
711

ext/reflection/php_reflection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6547,6 +6547,7 @@ static int call_attribute_constructor(
65476547
dummy_func.type = ZEND_USER_FUNCTION;
65486548
dummy_func.common.fn_flags =
65496549
attr->flags & ZEND_ATTRIBUTE_STRICT_TYPES ? ZEND_ACC_STRICT_TYPES : 0;
6550+
dummy_func.common.fn_flags |= ZEND_ACC_CALL_VIA_TRAMPOLINE;
65506551
dummy_func.op_array.filename = filename;
65516552

65526553
dummy_opline.opcode = ZEND_DO_FCALL;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #81430 (Attribute instantiation frame accessing invalid frame pointer)
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
memory_limit=20M
7+
zend_test.observer.enabled=1
8+
zend_test.observer.observe_all=1
9+
--FILE--
10+
<?php
11+
12+
#[\Attribute]
13+
class A {
14+
private $a;
15+
public function __construct() {
16+
}
17+
}
18+
19+
#[A]
20+
function B() {}
21+
22+
$r = new \ReflectionFunction("B");
23+
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
24+
?>
25+
--EXPECTF--
26+
<!-- init '%s' -->
27+
<file '%s'>
28+
<!-- init A::__construct() -->
29+
<A::__construct>
30+
</A::__construct>
31+
</file '%s'>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #81430 (Attribute instantiation leaves dangling execute_data pointer)
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
memory_limit=20M
7+
zend_test.observer.enabled=1
8+
zend_test.observer.observe_all=1
9+
--FILE--
10+
<?php
11+
12+
#[\Attribute]
13+
class A {
14+
public function __construct() {
15+
array_map("str_repeat", ["\xFF"], [100000000]); // cause a bailout
16+
}
17+
}
18+
19+
#[A]
20+
function B() {}
21+
22+
$r = new \ReflectionFunction("B");
23+
call_user_func([$r->getAttributes(A::class)[0], 'newInstance']);
24+
?>
25+
--EXPECTF--
26+
<!-- init '%s' -->
27+
<file '%s'>
28+
<!-- init A::__construct() -->
29+
<A::__construct>
30+
31+
Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
32+
</A::__construct>
33+
</file '%s'>

0 commit comments

Comments
 (0)