Skip to content

Fix GH-22112: assertion when error handler throws during NaN coercion#22114

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22112-nan-coercion-eg-exception
Open

Fix GH-22112: assertion when error handler throws during NaN coercion#22114
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22112-nan-coercion-eg-exception

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented May 21, 2026

Recv-arg verification for a userland function asserts !EG(exception) after a successful weak coercion. zend_parse_arg_bool_weak and zend_parse_arg_str_weak returned success without checking whether the NaN-coerced-to-bool/string warning had triggered a throw from the user error handler. Mirror the post-warning check in zend_parse_arg_long_weak.

Fixes #22112

zend_parse_arg_bool_weak and zend_parse_arg_str_weak could return success
with EG(exception) already set, because zend_is_true and convert_to_string
emit the NaN coercion warning without checking whether the user error
handler threw. Recv-arg verification for a userland function then took
the no-check ZEND_VM_NEXT_OPCODE branch, aborting on
ZEND_ASSERT(!EG(exception)). Mirror the existing check in
zend_parse_arg_long_weak and propagate failure when the warning leaves
an exception pending.

Fixes phpGH-22112
Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely a bug already in 8.5 so needs to be backported.

Also do not use exceptions defined in extensions when testing core functionality.

<?php

set_error_handler(function ($errno, $errstr) {
throw new RuntimeException($errstr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException($errstr);
throw new Exception($errstr);

Comment on lines +20 to +30
try {
take_bool($nan);
} catch (RuntimeException $e) {
echo "bool: ", $e->getMessage(), "\n";
}

try {
take_string($nan);
} catch (RuntimeException $e) {
echo "string: ", $e->getMessage(), "\n";
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {
take_bool($nan);
} catch (RuntimeException $e) {
echo "bool: ", $e->getMessage(), "\n";
}
try {
take_string($nan);
} catch (RuntimeException $e) {
echo "string: ", $e->getMessage(), "\n";
}
try {
take_bool($nan);
} catch (Exception $e) {
echo "bool: ", $e->getMessage(), "\n";
}
try {
take_string($nan);
} catch (Exception $e) {
echo "string: ", $e->getMessage(), "\n";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion failure at Zend/zend_vm_execute.h zend_verify_recv_arg_type_helper_SPEC

2 participants