History log of /PHP-8.0/ext/ffi/tests/gh7867.phpt (Results 1 – 1 of 1)
Revision Date Author Comments
# 703cac33 10-Jan-2022 Christoph M. Becker

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 regar

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.

show more ...