Commit b4b74114000 for php
commit b4b741140001bb667d85142c769db23279684ac5
Author: Tomasz Kowalczyk <tomasz@kowalczyk.cc>
Date: Thu Nov 26 19:49:31 2026 +0100
Fix GH-25788: clone() with properties corrupts memory with JIT when __clone() keeps a reference and the result is discarded (#25787)
clone() with properties calls __clone() on the returned object, and
__clone() can keep a reference to $this. The stub still declared
@refcount 1, which lets function JIT and tracing JIT destroy the object when
the result is discarded while that reference still uses it. Drop the
annotation.
diff --git a/NEWS b/NEWS
index 3b3e0159984..5af0b74016a 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,8 @@ PHP NEWS
. Fixed bug GH-25313 (Assertion !EG(exception) in ZEND_FE_FREE when unpacking
a generator into a by-ref parameter throws). (ndossche)
. Fix OSS-Fuzz #588264417. (ndossche)
+ . Fixed bug GH-25788 (clone() with properties corrupts memory with JIT when
+ __clone() keeps a reference and the result is discarded). (Tomasz Kowalczyk)
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h
index 76d63862cbc..b7b8ef6952d 100644
--- a/Zend/Optimizer/zend_func_infos.h
+++ b/Zend/Optimizer/zend_func_infos.h
@@ -1,7 +1,6 @@
/* This is a generated file, edit the .stub.php files instead. */
static const func_info_t func_infos[] = {
- F1("clone", MAY_BE_OBJECT),
F1("zend_version", MAY_BE_STRING),
FN("func_get_args", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY),
F1("get_class_vars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
diff --git a/Zend/tests/clone/gh25788.phpt b/Zend/tests/clone/gh25788.phpt
new file mode 100644
index 00000000000..2c388c6512e
--- /dev/null
+++ b/Zend/tests/clone/gh25788.phpt
@@ -0,0 +1,42 @@
+--TEST--
+GH-25788: clone() with properties corrupts memory with JIT when __clone() keeps a reference and the result is discarded
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=function
+opcache.jit_buffer_size=64M
+opcache.file_update_protection=0
+--FILE--
+<?php
+
+class Row {
+ public static array $rows = [];
+
+ public int $id = 1;
+
+ public function __clone() {
+ self::$rows[] = $this;
+ }
+
+ public function __destruct() { echo "destruct\n"; }
+}
+
+function test(Row $row) {
+ clone($row, ['id' => 2]);
+}
+
+test(new Row());
+var_dump(Row::$rows);
+?>
+--EXPECTF--
+destruct
+array(1) {
+ [0]=>
+ object(Row)#%d (1) {
+ ["id"]=>
+ int(2)
+ }
+}
+destruct
diff --git a/Zend/zend_builtin_functions.stub.php b/Zend/zend_builtin_functions.stub.php
index 9b2267b531e..59340a15d47 100644
--- a/Zend/zend_builtin_functions.stub.php
+++ b/Zend/zend_builtin_functions.stub.php
@@ -7,7 +7,6 @@ class stdClass
{
}
-/** @refcount 1 */
function clone(object $object, array $withProperties = []): object {}
function exit(string|int $status = 0): never {}
diff --git a/Zend/zend_builtin_functions_arginfo.h b/Zend/zend_builtin_functions_arginfo.h
index cf349b551ac..8dba24e1ecd 100644
Binary files a/Zend/zend_builtin_functions_arginfo.h and b/Zend/zend_builtin_functions_arginfo.h differ