Skip to content

Commit db54a83

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17246: GC during SCCP causes segfault
2 parents bf3673a + e45fdd2 commit db54a83

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,10 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21652165
*/
21662166
from_shared_memory = false;
21672167
if (persistent_script) {
2168+
/* See GH-17246: we disable GC so that user code cannot be executed during the optimizer run. */
2169+
bool orig_gc_state = gc_enable(false);
21682170
persistent_script = cache_script_in_shared_memory(persistent_script, key, &from_shared_memory);
2171+
gc_enable(orig_gc_state);
21692172
}
21702173

21712174
/* Caching is disabled, returning op_array;

ext/opcache/tests/jit/gh17246.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Need to cause a trace exit, so extend non existent class
4+
class MyXSLTProcessor extends NonExistentClass {
5+
public function registerCycle() {
6+
[[$this]]; // Non trivial array
7+
}
8+
}

ext/opcache/tests/jit/gh17246.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-17246 (Nested shm protections cause segfault)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.protect_memory=1
7+
opcache.jit_buffer_size=32M
8+
opcache.jit=1254
9+
--FILE--
10+
<?php
11+
12+
class Test
13+
{
14+
private $field;
15+
16+
public function __construct()
17+
{
18+
$this->field = function() {};
19+
}
20+
21+
public function __destruct()
22+
{
23+
// Necessary because we need to invoke tracing JIT during destruction
24+
}
25+
}
26+
27+
for ($i = 0; $i < 10000; ++$i) {
28+
$obj = new Test();
29+
}
30+
31+
require __DIR__.'/gh17246.inc';
32+
33+
?>
34+
--EXPECTF--
35+
Fatal error: Uncaught Error: Class "NonExistentClass" not found in %s:%d
36+
Stack trace:
37+
#0 %s(%d): require()
38+
#1 {main}
39+
thrown in %s on line %d

0 commit comments

Comments
 (0)