php-src/ext/ffi
Christoph M. Becker 703cac33db
Fix GH-7867: FFI::cast() from pointer to array is broken
Casting from pointer to array is special, so we must not fall back to
the general FFI casting.  There is a particular issue regarding the
size comparison, namely that the pointer size is always 8 for 64bit
architectures, but the size of an array is determined by its
declaration, so as is casting a pointer to an array with more than 8
elements would fail, but casting to an array with less than 9 elements
succeeds, but the internal pointer would point to some arbitrary
memory.

We fix this by properly supporting the cast.  An alternative would be
to deny this kind of cast generally, since it is not necessarily safe.
However, FFI isn't necessarily safe anyway.

We also check pointer/array type compatibility when casting.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-7876.
2022-01-10 23:58:39 +01:00
..
tests Fix GH-7867: FFI::cast() from pointer to array is broken 2022-01-10 23:58:39 +01:00
config.m4 ext/ffi: Remove symbol check for ffi_open 2019-06-03 09:19:25 +02:00
config.w32 Implement #78270: Support __vectorcall convention with FFI 2019-10-29 08:57:43 +01:00
CREDITS
ffi_arginfo.h Add missing classes to stubs 2021-02-09 22:38:06 +01:00
ffi_parser.c Merge branch 'PHP-7.4' into PHP-8.0 2021-09-15 14:49:35 +03:00
ffi.c Fix GH-7867: FFI::cast() from pointer to array is broken 2022-01-10 23:58:39 +01:00
ffi.g Merge branch 'PHP-7.4' into PHP-8.0 2021-09-15 14:49:35 +03:00
ffi.stub.php Add missing classes to stubs 2021-02-09 22:38:06 +01:00
php_ffi.h Explicitly declare the char as signed in zend_ffi_val. 2020-03-26 10:28:38 +03:00