[php-src] PHP-8.4: Fix GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (#25784)
| From: | Tomasz Kowalczyk via GitHub | Date: | Thu, 26 Nov 2026 18:47:30 +0000 |
| Subject: | [php-src] PHP-8.4: Fix GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (#25784) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144231@lists.php.net to get a copy of this message | ||
Author: Tomasz Kowalczyk (thunderer)
Committer: GitHub (web-flow)
Pusher: kamil-tekiela
Date: 2026-11-26T18:47:26Z
Commit: https://github.com/php/php-src/commit/8084ab369d1aacdfccf3244174a7d73551a3466c
Raw diff: https://github.com/php/php-src/commit/8084ab369d1aacdfccf3244174a7d73551a3466c.diff
Fix GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the
result is discarded (#25784)
mysqli_fetch_object() calls the constructor on the returned object, and the
constructor 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.
Changed paths:
A ext/mysqli/tests/gh25779.phpt
M NEWS
M Zend/Optimizer/zend_func_infos.h
M ext/mysqli/mysqli.stub.php
M ext/mysqli/mysqli_arginfo.h
Diff:
diff --git a/NEWS b/NEWS
index 7766b7462ccb..c71a4275fa11 100644
--- a/NEWS
+++ b/NEWS
@@ -116,6 +116,11 @@ PHP NEWS
. Fixed the JIT freeing the string returned by mb_encode_mimeheader() or
mb_output_handler() while it is still in use. (Ilia Alshanetsky)
+- MySQLi:
+ . Fixed bug GH-25779 (mysqli_fetch_object() crashes with JIT when the
+ constructor keeps a reference and the result is discarded).
+ (Tomasz Kowalczyk)
+
- Opcache:
. Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
(waroad)
diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h
index faff2f43b5c7..ce6369193014 100644
--- a/Zend/Optimizer/zend_func_infos.h
+++ b/Zend/Optimizer/zend_func_infos.h
@@ -249,7 +249,6 @@ static const func_info_t func_infos[] = {
F1("mysqli_fetch_all",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
F1("mysqli_fetch_array",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
F1("mysqli_fetch_assoc",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
- F1("mysqli_fetch_object", MAY_BE_OBJECT|MAY_BE_NULL|MAY_BE_FALSE),
F1("mysqli_fetch_row",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
F1("mysqli_get_connection_stats",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
F1("mysqli_get_client_stats",
MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),
diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php
index de287b347dee..23b215565329 100644
--- a/ext/mysqli/mysqli.stub.php
+++ b/ext/mysqli/mysqli.stub.php
@@ -1423,7 +1423,6 @@ function mysqli_fetch_array(mysqli_result $result, int $mode = MYSQLI_BOTH):
arr
*/
function mysqli_fetch_assoc(mysqli_result $result): array|null|false {}
-/** @refcount 1 */
function mysqli_fetch_object(mysqli_result $result, string $class = "stdClass", array
$constructor_args = []): object|null|false {}
/**
diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h
index e45c3550a6c5..636ee9a5dfcf 100644
--- a/ext/mysqli/mysqli_arginfo.h
+++ b/ext/mysqli/mysqli_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 32baf7b0642af68dea551687bc44ae47d708d810 */
+ * Stub hash: 1e669ba66edc3e15201e15e67661794b11a3929e */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1,
MAY_BE_LONG|MAY_BE_STRING)
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
diff --git a/ext/mysqli/tests/gh25779.phpt b/ext/mysqli/tests/gh25779.phpt
new file mode 100644
index 000000000000..d89f8deb180a
--- /dev/null
+++ b/ext/mysqli/tests/gh25779.phpt
@@ -0,0 +1,47 @@
+--TEST--
+GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the
result is discarded
+--EXTENSIONS--
+mysqli
+opcache
+--SKIPIF--
+<?php
+require_once __DIR__ . '/test_setup/test_helpers.inc';
+mysqli_check_skip_test();
+?>
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit=function
+opcache.jit_buffer_size=64M
+opcache.file_update_protection=0
+--FILE--
+<?php
+require_once __DIR__ . '/test_setup/test_helpers.inc';
+
+class Row {
+ public static array $rows = [];
+
+ public function __construct() {
+ self::$rows[] = $this;
+ }
+
+ public function __destruct() { echo "destruct\n"; }
+}
+
+function test(mysqli_result $result) {
+ mysqli_fetch_object($result, Row::class);
+}
+
+$link = default_mysqli_connect();
+test(mysqli_query($link, "SELECT 1 AS id"));
+var_dump(Row::$rows);
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ object(Row)#%d (1) {
+ ["id"]=>
+ string(1) "1"
+ }
+}
+destruct