Skip to content

Commit 03bb112

Browse files
authored
Fix GH-16984: function JIT overflow bug (#17015)
1 parent d7a37cc commit 03bb112

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

ext/opcache/jit/zend_jit_ir.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7204,9 +7204,9 @@ static int zend_jit_cmp(zend_jit_ctx *jit,
72047204

72057205
while (n) {
72067206
n--;
7207-
ir_IF_TRUE(end_inputs->refs[n]);
7207+
jit_IF_TRUE_FALSE_ex(jit, end_inputs->refs[n], label);
72087208
ir_END_list(true_inputs);
7209-
ir_IF_FALSE(end_inputs->refs[n]);
7209+
jit_IF_TRUE_FALSE_ex(jit, end_inputs->refs[n], label2);
72107210
ir_END_list(false_inputs);
72117211
}
72127212
ir_MERGE_list(true_inputs);

ext/opcache/tests/jit/gh16984.phpt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
GH-16984 (function JIT overflow bug)
3+
--EXTENSIONS--
4+
opcache
5+
--SKIPIF--
6+
<?php if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?>
7+
--INI--
8+
opcache.enable=1
9+
opcache.enable_cli=1
10+
opcache.file_update_protection=0
11+
opcache.jit_buffer_size=32M
12+
opcache.jit=function
13+
--FILE--
14+
<?php
15+
16+
final class Test {
17+
public int $integer = -1;
18+
19+
public function foo(int $x) {
20+
return $x;
21+
}
22+
}
23+
24+
function foo(Test $test, int $value) {
25+
$val = $test->foo($value);
26+
if ($val <= PHP_INT_MAX) {
27+
$test->integer = $val;
28+
}
29+
}
30+
31+
function main() {
32+
$test = new Test;
33+
foo($test, 9223372036854775806);
34+
foo($test, 9223372036854775807); // Also reproduces without this call, but this imitates the psalm code
35+
var_dump($test->integer);
36+
}
37+
38+
main();
39+
?>
40+
--EXPECT--
41+
int(9223372036854775807)

0 commit comments

Comments
 (0)