-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #79177: FFI doesn't handle well PHP exceptions within callback
We have to error on unhandled exceptions in FFI callbacks, to avoid passing back undefined values. This has been discussed and agreed upon in a previous PR[1]. [1] <#5120> Closes GH-6366.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
Bug #79177 (FFI doesn't handle well PHP exceptions within callback) | ||
--SKIPIF-- | ||
<?php | ||
require_once('skipif.inc'); | ||
require_once('utils.inc'); | ||
try { | ||
ffi_cdef("extern void *zend_printf;", ffi_get_php_dll_name()); | ||
} catch (Throwable $e) { | ||
die('skip PHP symbols not available'); | ||
} | ||
?> | ||
--FILE-- | ||
<?php | ||
require_once('utils.inc'); | ||
$php = ffi_cdef(" | ||
typedef char (*zend_write_func_t)(const char *str, size_t str_length); | ||
extern zend_write_func_t zend_write; | ||
", ffi_get_php_dll_name()); | ||
|
||
echo "Before\n"; | ||
|
||
$originalHandler = clone $php->zend_write; | ||
$php->zend_write = function($str, $len): string { | ||
throw new \RuntimeException('Not allowed'); | ||
}; | ||
try { | ||
echo "After\n"; | ||
} catch (\Throwable $exception) { | ||
// Do not output anything here, as handler is overridden | ||
} finally { | ||
$php->zend_write = $originalHandler; | ||
} | ||
if (isset($exception)) { | ||
echo $exception->getMessage(), PHP_EOL; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Before | ||
|
||
Warning: Uncaught RuntimeException: Not allowed in %s:%d | ||
Stack trace: | ||
#0 %s(%d): {closure}('After\n', 6) | ||
#1 {main} | ||
thrown in %s on line %d | ||
|
||
Fatal error: Throwing from FFI callbacks is not allowed in %s on line %d |