Skip to content

Commit fbab135

Browse files
committed
Fix lazy proxy bailing __clone assertion
When __clone of the underlying object fails with a bailout, ZEND_ASSERT(res == SUCCESS) in zend_lazy_object_del_info() will fail because the info has not been registered yet. Only copy OBJ_EXTRA_FLAGS once the info has been successfully registered. Fixes GH-20905
1 parent ee5fc4a commit fbab135

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-20905: Lazy proxy bailing __clone assertion
3+
--FILE--
4+
<?php
5+
6+
function test() {
7+
function f() {}
8+
}
9+
10+
class A {
11+
public $_;
12+
public function __clone() {
13+
test();
14+
}
15+
}
16+
17+
test();
18+
clone (new ReflectionClass(A::class))->newLazyProxy(fn() => new A);
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: Cannot redeclare function f() (previously declared in %s:%d) in %s on line %d

Zend/zend_lazy_objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,11 @@ zend_object *zend_lazy_object_clone(zend_object *old_obj)
744744
}
745745
}
746746

747-
OBJ_EXTRA_FLAGS(new_proxy) = OBJ_EXTRA_FLAGS(old_obj);
748-
749747
zend_lazy_object_info *new_info = emalloc(sizeof(*info));
750748
*new_info = *info;
751749
new_info->u.instance = zend_objects_clone_obj(info->u.instance);
752750

751+
OBJ_EXTRA_FLAGS(new_proxy) = OBJ_EXTRA_FLAGS(old_obj);
753752
zend_lazy_object_set_info(new_proxy, new_info);
754753

755754
return new_proxy;

0 commit comments

Comments
 (0)