Skip to content

Commit 193f28c

Browse files
committed
Fixed bug #78010
Prevent the gc_info from becoming all zero for a registered root by setting the top bit to one for compressed root addresses.
1 parent 3eb057c commit 193f28c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

Zend/tests/bug78010.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #78010: Segmentation fault during GC
3+
--INI--
4+
memory_limit=2G
5+
--FILE--
6+
<?php
7+
8+
class foo
9+
{
10+
public function __construct()
11+
{
12+
$this->x = $this;
13+
14+
for ($i = 0; $i < 898; $i++) { //Will not trigger with <898
15+
$obj = [new stdClass, new stdClass]; //This must have at least 2 elements
16+
$this->y[] = $obj;
17+
}
18+
}
19+
}
20+
21+
for ($i = 0; $i < 2; ++$i) { //This must run >=2 (increasing the number of elements in the array *2 will not do)
22+
$x = []; //This must be reset
23+
foreach (array_fill(0, 389, 'x') as &$params) { //Will not trigger <389
24+
$x[] = new foo;
25+
}
26+
}
27+
28+
echo "Completed\n";
29+
30+
?>
31+
--EXPECT--
32+
Completed

Zend/zend_gc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
#define GC_DEFAULT_BUF_SIZE (16 * 1024)
151151
#define GC_BUF_GROW_STEP (128 * 1024)
152152

153-
#define GC_MAX_UNCOMPRESSED (1024 * 1024)
153+
#define GC_MAX_UNCOMPRESSED (512 * 1024)
154154
#define GC_MAX_BUF_SIZE 0x40000000
155155

156156
#define GC_THRESHOLD_DEFAULT 10000
@@ -314,7 +314,10 @@ static void gc_stack_free(gc_stack *stack)
314314

315315
static zend_always_inline uint32_t gc_compress(uint32_t idx)
316316
{
317-
return idx % GC_MAX_UNCOMPRESSED;
317+
if (EXPECTED(idx < GC_MAX_UNCOMPRESSED)) {
318+
return idx;
319+
}
320+
return (idx % GC_MAX_UNCOMPRESSED) | GC_MAX_UNCOMPRESSED;
318321
}
319322

320323
static zend_always_inline gc_root_buffer* gc_decompress(zend_refcounted *ref, uint32_t idx)

0 commit comments

Comments
 (0)