Skip to content

Assertion `size >= page_size + 1 * page_size' failed. #10249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changochen opened this issue Jan 6, 2023 · 2 comments
Closed

Assertion `size >= page_size + 1 * page_size' failed. #10249

Changochen opened this issue Jan 6, 2023 · 2 comments

Comments

@Changochen
Copy link

Description

The following code:

<?php
$callback = function () {};
ini_set("fiber.stack_size", "");
$fiber = new Fiber($callback);
$fiber->start();

Resulted in this output:

php_asan/Zend/zend_fibers.c:205: zend_fiber_stack *zend_fiber_stack_allocate(size_t): Assertion `size >= page_size + 1 * page_size' failed.

git commit: 84af629

Build config:

./configure --disable-all --enable-address-sanitizer --disable-phpdbg --disable-cgi --with-pic --enable-debug-assertions
make -j

PHP Version

PHP 8.3.0-dev

Operating System

No response

@nielsdos
Copy link
Member

nielsdos commented Jan 6, 2023

I confirm this happens on 8.1 and higher.

The size in zend_fiber_stack_allocate becomes zero. So I guess instead of asserting, we should error out or print a warning and set size to the minimum (page_size + ZEND_FIBER_GUARD_PAGES * page_size).

EDIT: Given that other stack-related issues in that function throw an exception, I guess this should throw as well?
EDIT 2: if an error exception is appropriate, the following patch is maybe good? (applyable using git apply on branch PHP-8.1)

diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c
index 1fec85528f..543da605bd 100644
--- a/Zend/zend_fibers.c
+++ b/Zend/zend_fibers.c
@@ -174,8 +174,12 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
 {
 	void *pointer;
 	const size_t page_size = zend_fiber_get_page_size();
+	const size_t minimum_stack_size = page_size + ZEND_FIBER_GUARD_PAGES * page_size;
 
-	ZEND_ASSERT(size >= page_size + ZEND_FIBER_GUARD_PAGES * page_size);
+	if (size < minimum_stack_size) {
+		zend_throw_exception_ex(NULL, 0, "Fiber stack size is too small, it needs to be at least %zu bytes", minimum_stack_size);
+		return NULL;
+	}
 
 	const size_t stack_size = (size + page_size - 1) / page_size * page_size;
 	const size_t alloc_size = stack_size + ZEND_FIBER_GUARD_PAGES * page_size;

If it look sensible to the maintainers I'll make a PR

@trowski
Copy link
Member

trowski commented Jan 10, 2023

This looks reasonable, please do make a PR. Thank you!

nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants