Skip to content

Commit

Permalink
Fix phpGH-17654: JIT OPcache with CRTO Modes XX14, XX34, XX15 and XX3…
Browse files Browse the repository at this point in the history
…5 Crash The Application

This test has two classes that use the same trait. In function JIT mode
the same cache slot will be used. This causes problems because it is
primed for the first class and then reused for the second class,
resulting in an incorrect type check failure.

The current check for a megamorphic trait call requires current_frame to
not be NULL, but this is only set in tracing mode and not in function
mode.

This patch corrects the check.
  • Loading branch information
nielsdos committed Jan 31, 2025
1 parent f8b57ff commit 7e8fc4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ext/opcache/jit/zend_jit_arm64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -9200,9 +9200,9 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
func = call_info->callee_func;
}
if ((op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)
&& JIT_G(current_frame)
&& JIT_G(current_frame)->call
&& !JIT_G(current_frame)->call->func) {
&& (!JIT_G(current_frame) ||
!JIT_G(current_frame)->call ||
!JIT_G(current_frame)->call->func)) {
call_info = NULL; func = NULL; /* megamorphic call from trait */
}
}
Expand Down
6 changes: 3 additions & 3 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -9931,9 +9931,9 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
func = call_info->callee_func;
}
if ((op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)
&& JIT_G(current_frame)
&& JIT_G(current_frame)->call
&& !JIT_G(current_frame)->call->func) {
&& (!JIT_G(current_frame) ||
!JIT_G(current_frame)->call ||
!JIT_G(current_frame)->call->func)) {
call_info = NULL; func = NULL; /* megamorphic call from trait */
}
}
Expand Down
38 changes: 38 additions & 0 deletions ext/opcache/tests/jit/gh17654.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
GH-17654 (JIT OPcache with CRTO Modes XX14, XX34, XX15 and XX35 Crash The Application)
--EXTENSIONS--
opcache
--INI--
opcache.jit=1214
opcache.jit_buffer_size=16M
--FILE--
<?php
trait TestTrait {
public function addUnit(string $x) {
self::addRawUnit($this, $x);
}

public function addRawUnit(self $data, string $x) {
var_dump($x);
}
}

class Test {
use TestTrait;
}

class Test2 {
use TestTrait;
}

function main()
{
(new Test2)->addUnit("test2");
(new Test)->addUnit("test");
}

main();
?>
--EXPECT--
string(5) "test2"
string(4) "test"

0 comments on commit 7e8fc4d

Please # to comment.