Skip to content

Assertion failure in Zend/zend_builtin_functions.c:1893 #16230

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
YuanchengJiang opened this issue Oct 5, 2024 · 4 comments
Closed

Assertion failure in Zend/zend_builtin_functions.c:1893 #16230

YuanchengJiang opened this issue Oct 5, 2024 · 4 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$test = new _ZendTestFiber(function (): void {
$fiber->start();
});
var_dump($test->start());

Resulted in this output:

/php-src/Zend/zend_builtin_functions.c:1893: void zend_fetch_debug_backtrace(zval *, int, int, int): Assertion `call->func' failed.
Aborted (core dumped)

Not sure if it can be triggered in other ways without testclass.

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

@nielsdos
Copy link
Member

nielsdos commented Oct 5, 2024

That assertion was added in #15952, but the assert just seems to ignore the existance of fibers afaict

@nielsdos
Copy link
Member

nielsdos commented Oct 5, 2024

Test can be simplified to:

$test = new _ZendTestFiber(function (): void {
    print_r(debug_backtrace());
});
$test->start();

I cannot trigger this with Fiber, only with the internal test class... Would need to think more about this.
Removing the assert works fine, but I'm not so sure that's the right thing to do.

@iluuu1994
Copy link
Member

It seems _ZendTestFiber installs an empty frame, for some reason:

execute_data = (zend_execute_data *) stack->top;
memset(execute_data, 0, sizeof(zend_execute_data));
EG(current_execute_data) = execute_data;

Apparently, this is ok for the top function, as it exists the loop:

if (!prev) {
/* add frame for a handler call without {main} code */
if (EXPECTED((ZEND_CALL_INFO(call) & ZEND_CALL_TOP_FUNCTION) == 0)) {
break;
}

I don't know if there are any extensions that do this, but it seems like they would have already reported the issue if so. So maybe let's just set it to a dummy function?

diff --git a/ext/zend_test/fiber.c b/ext/zend_test/fiber.c
index 30dbfa06e5..4518c26c6f 100644
--- a/ext/zend_test/fiber.c
+++ b/ext/zend_test/fiber.c
@@ -91,6 +91,7 @@ static ZEND_STACK_ALIGNED void zend_test_fiber_execute(zend_fiber_transfer *tran
 		execute_data = (zend_execute_data *) stack->top;
 
 		memset(execute_data, 0, sizeof(zend_execute_data));
+		execute_data->func = (zend_function *) &zend_pass_function;
 
 		EG(current_execute_data) = execute_data;
 		EG(jit_trace_num) = 0;

We can also remove the assert, if you think that's preferable.

@nielsdos
Copy link
Member

nielsdos commented Oct 7, 2024

@iluuu1994 Your patch suggestion makes sense to me.

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