Skip to content

Commit 88110bb

Browse files
committed
Fix GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded
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.
1 parent c726574 commit 88110bb

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

‎NEWS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ PHP NEWS
116116
. Fixed the JIT freeing the string returned by mb_encode_mimeheader() or
117117
mb_output_handler() while it is still in use. (Ilia Alshanetsky)
118118

119+
- MySQLi:
120+
. Fixed bug GH-25779 (mysqli_fetch_object() crashes with JIT when the
121+
constructor keeps a reference and the result is discarded).
122+
(Tomasz Kowalczyk)
123+
119124
- Opcache:
120125
. Fixed bug GH-24801 (JIT: SIGFPE in ir_fold MUL_OV constant folding).
121126
(waroad)

‎Zend/Optimizer/zend_func_infos.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ static const func_info_t func_infos[] = {
249249
F1("mysqli_fetch_all", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
250250
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),
251251
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),
252-
F1("mysqli_fetch_object", MAY_BE_OBJECT|MAY_BE_NULL|MAY_BE_FALSE),
253252
F1("mysqli_fetch_row", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY|MAY_BE_NULL|MAY_BE_FALSE),
254253
F1("mysqli_get_connection_stats", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
255254
F1("mysqli_get_client_stats", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),

‎ext/mysqli/mysqli.stub.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ function mysqli_fetch_array(mysqli_result $result, int $mode = MYSQLI_BOTH): arr
14231423
*/
14241424
function mysqli_fetch_assoc(mysqli_result $result): array|null|false {}
14251425

1426-
/** @refcount 1 */
14271426
function mysqli_fetch_object(mysqli_result $result, string $class = "stdClass", array $constructor_args = []): object|null|false {}
14281427

14291428
/**

‎ext/mysqli/mysqli_arginfo.h‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ext/mysqli/tests/gh25779.phpt‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
GH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded
3+
--EXTENSIONS--
4+
mysqli
5+
opcache
6+
--SKIPIF--
7+
<?php
8+
require_once __DIR__ . '/test_setup/test_helpers.inc';
9+
mysqli_check_skip_test();
10+
?>
11+
--INI--
12+
opcache.enable=1
13+
opcache.enable_cli=1
14+
opcache.jit=function
15+
opcache.jit_buffer_size=64M
16+
opcache.file_update_protection=0
17+
--FILE--
18+
<?php
19+
require_once __DIR__ . '/test_setup/test_helpers.inc';
20+
21+
class Row {
22+
public static array $rows = [];
23+
24+
public function __construct() {
25+
self::$rows[] = $this;
26+
}
27+
}
28+
29+
function test(mysqli_result $result) {
30+
mysqli_fetch_object($result, Row::class);
31+
}
32+
33+
$link = default_mysqli_connect();
34+
test(mysqli_query($link, "SELECT 1 AS id"));
35+
var_dump(Row::$rows);
36+
?>
37+
--EXPECTF--
38+
array(1) {
39+
[0]=>
40+
object(Row)#%d (1) {
41+
["id"]=>
42+
string(1) "1"
43+
}
44+
}

0 commit comments

Comments
 (0)