Skip to content

Commit e45fdd2

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

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ PHP NEWS
6464
ZEND_FETCH_DIM_FUNC_ARG). (nielsdos, Dmitry)
6565
. Fixed bug GH-17151 (Incorrect RC inference of op1 of FETCH_OBJ and
6666
INIT_METHOD_CALL). (Dmitry, ilutov)
67+
. Fixed bug GH-17246 (GC during SCCP causes segfault). (Dmitry)
6768

6869
- PCNTL:
6970
. Fix memory leak in cleanup code of pcntl_exec() when a non stringable

ext/opcache/ZendAccelerator.c

+3
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,10 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21642164
*/
21652165
from_shared_memory = false;
21662166
if (persistent_script) {
2167+
/* See GH-17246: we disable GC so that user code cannot be executed during the optimizer run. */
2168+
bool orig_gc_state = gc_enable(false);
21672169
persistent_script = cache_script_in_shared_memory(persistent_script, key, &from_shared_memory);
2170+
gc_enable(orig_gc_state);
21682171
}
21692172

21702173
/* Caching is disabled, returning op_array;

ext/opcache/tests/jit/gh17246.inc

+8
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

+39
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)