Skip to content

Commit e3c2301

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-20483: ASAN stack overflow with small fiber.stack_size INI value.
2 parents 3a2868f + d2c5b3b commit e3c2301

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
in $selectors to be lowercase). (ndossche)
1919
. Fix missing NUL byte check on C14NFile(). (ndossche)
2020

21+
- Fibers:
22+
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
23+
small value). (David Carlier)
24+
2125
- Opcache:
2226
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
2327
buffer). (Arnaud)

Zend/tests/fibers/gh20483.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-20483 (ASAN stack overflow with small fiber.stack_size INI value)
3+
--INI--
4+
fiber.stack_size=1024
5+
--FILE--
6+
<?php
7+
$callback = function () {};
8+
$fiber = new Fiber($callback);
9+
try {
10+
$fiber->start();
11+
} catch (Exception $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
?>
15+
--EXPECTF--
16+
Fiber stack size is too small, it needs to be at least %d bytes

Zend/zend_fibers.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
207207
{
208208
void *pointer;
209209
const size_t page_size = zend_fiber_get_page_size();
210-
const size_t minimum_stack_size = page_size + ZEND_FIBER_GUARD_PAGES * page_size;
210+
const size_t minimum_stack_size = page_size + ZEND_FIBER_GUARD_PAGES * page_size
211+
#ifdef __SANITIZE_ADDRESS__
212+
// necessary correction due to ASAN redzones
213+
* 6
214+
#endif
215+
;
211216

212217
if (size < minimum_stack_size) {
213218
zend_throw_exception_ex(NULL, 0, "Fiber stack size is too small, it needs to be at least %zu bytes", minimum_stack_size);

0 commit comments

Comments
 (0)