-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Named arguments in CTE functions cause a segfault #10801
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
Comments
I can confirm that this crashes. In fact, any compile-time-evaluated function where the programmer uses named arguments will crash because For example, even something like: <?php
echo strstr(needle: 'a', haystack: 'aaa'); will crash after marking that function as CTE (like you did in your recent PR). And it is even triggerable with functions which are CTE right now already: <?php
echo count(value: []); This definitely needs fixing, I'll do that tonight. |
hash
as CTE leads to segfaulthash
as CTE leads to segfault)
hash
as CTE leads to segfault)
I edited the title so the root cause is in the title. Others can then also more easily find these issues. |
Interesting bug. I can't always reproduce it with the simple reproducer I gave. Furthermore, I found 2 other weird behaviours. If you use ASAN, you'll find that the following works correctly without opcache: <?php
print_r(array_keys(array: [1], strict: true, filter_value: 1)); but if you enable opcache: it crashes with a segfault on an invalid pointer. I added a printf to show what types of zvals get destroyed and I see that the crash happens when a zval of type "32" gets destroyed. This is during execution and is not a valid type. It tries to destroy a reference which of course fails and crashes... It appears this is the argument sent to print_r which gets destroyed due to an exception. And the argument probably happens because the zval is invalid... It this destruction were not to happen we get the EX(call) failure from earlier again. Probably also caused by the invalid zval in the first place. Also worth noting, if I first assign the return value of If I change the
I'm out of time for today so I'll have to resume some other time. |
It's an optimizer bug in EDIT: according to https://wiki.php.net/rfc/named_params this is expected. So I'll proceed with my opcode nr fix, unless I find something smart |
So I fixed the crash and random fatal error bug locally, but I found another bug in the process. |
Adding support for named parameters in CTE is not trivial, requires tens of lines of code extra instead of the few lines I had to change for the crash fix. So therefore I think that would be master-only. |
Fixes phpGH-10801 Named arguments are not supported by the constant evaluation routine, in the sense that they are ignored. This causes two issues: - It causes a crash because not all oplines belonging to the call are removed, which results in SEND_VA{L,R} which should've been removed. - It causes semantic issues (demonstrated in the test case). This case never worked anyway, leading to crashes or incorrect behaviour, so just prevent CTE of calls with named parameters for now. We can choose to support it later, but introducing support for this in a stable branch seems too dangerous. This patch does not change the removal of SEND_* opcodes in remove_call because the crash bug can't be triggered anymore with this patch as there are no named parameters anymore and no variadic CTE functions exist.
Fixes phpGH-10801 Named arguments are not supported by the constant evaluation routine, in the sense that they are ignored. This causes two issues: - It causes a crash because not all oplines belonging to the call are removed, which results in SEND_VA{L,R} which should've been removed. - It causes semantic issues (demonstrated in the test case). This case never worked anyway, leading to crashes or incorrect behaviour, so just prevent CTE of calls with named parameters for now. We can choose to support it later, but introducing support for this in a stable branch seems too dangerous. This patch does not change the removal of SEND_* opcodes in remove_call because the crash bug can't be triggered anymore with this patch as there are no named parameters anymore and no variadic CTE functions exist.
Fixes phpGH-10801 Named arguments are not supported by the constant evaluation routine, in the sense that they are ignored. This causes two issues: - It causes a crash because not all oplines belonging to the call are removed, which results in SEND_VA{L,R} which should've been removed. - It causes semantic issues (demonstrated in the test case). This case never worked anyway, leading to crashes or incorrect behaviour, so just prevent CTE of calls with named parameters for now. We can choose to support it later, but introducing support for this in a stable branch seems too dangerous. This patch does not change the removal of SEND_* opcodes in remove_call because the crash bug can't be triggered anymore with this patch as there are no named parameters anymore and no variadic CTE functions exist.
* PHP-8.1: Fix GH-10801: Named arguments in CTE functions cause a segfault
* PHP-8.2: Fix GH-10801: Named arguments in CTE functions cause a segfault
Description
The following code:
and
hash
function marked as CTE (like in https://github.com/php/php-src/blob/f16c3e1265/ext/hash/hash.stub.php#L12)Resulted in this output:
But I expected this output instead:
discovered in #10771, based on #10771 (comment) hash will be not supported as CTE, but I belive the segfault should be investigated, as it can be used from an extension on compile time for example
PHP Version
master
Operating System
any
The text was updated successfully, but these errors were encountered: