Skip to content

Commit 48aefb5

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20483: ASAN stack overflow with small fiber.stack_size INI value.
2 parents b3061df + 01bca99 commit 48aefb5

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
@@ -16,6 +16,10 @@ PHP NEWS
1616
with a given skeleton, locale, collapse type and identity fallback.
1717
(BogdanUngureanu)
1818

19+
- Fibers:
20+
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
21+
small value). (David Carlier)
22+
1923
- Opcache:
2024
. Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
2125
preloading). (Arnaud, welcomycozyhom)

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)