Bug #79177 [NEW]: FFI doesn't handle well PHP exceptions within callback body

From: Date: Mon, 27 Jan 2020 18:05:51 +0000
Subject: Bug #79177 [NEW]: FFI doesn't handle well PHP exceptions within callback body
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225163@lists.php.net to get a copy of this message
From:             lisachenko dot it at gmail dot com
Operating system: Unix
PHP version:      7.4.2
Package:          *Extensibility Functions
Bug Type:         Bug
Bug description:FFI doesn't handle well PHP exceptions within callback body

Description:
------------
If we define a C callback handler in PHP and this handler should return
a pointer (not a simple value like int, float, etc), then FFI doesn't
check if correct value was returned or not. For example when we throw
our custom exception within callback body.

This typically results in exception from FFI: Incompatible types when
assigning to type 'struct some_native_type*' from PHP 'unknown'

Exception is thrown because there is no check for Z_TYPE(retval) !=
IS_UNDEF inside FFI's function zend_ffi_callback_trampoline before call
to zend_ffi_zval_to_cdata(ret, ret_type, &retval)

Expected result:
----------------
Exception is thrown within callback and not from FFI itself about
missing type conversion

Actual result:
--------------
Incompatible types when assigning to type 'struct some_native_type*'
from PHP 'unknown'

-- 
Edit bug report at https://bugs.php.net/bug.php?id=79177&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79177&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79177&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79177&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79177&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79177&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79177&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79177&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79177&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79177&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79177&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79177&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79177&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79177&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79177&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79177&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79177&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79177&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#225163) next »