Bug #79125 [NEW]: FFI Struct Segfault

From: Date: Wed, 15 Jan 2020 19:11:59 +0000
Subject: Bug #79125 [NEW]: FFI Struct Segfault
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224923@lists.php.net to get a copy of this message
From: php at tim dot ainfach dot de Operating system: OSX 10.14.6 PHP version: 7.4.2RC1 Package: *Extensibility Functions Bug Type: Bug Bug description:FFI Struct Segfault Description: ------------ returning and directly using the result of a \FFI::cdef() function ends up in a void pointer. php-src/ext/ffi/ffi.c:1990: zend_ffi_cdata_get_debug_info: Assertion `0' failed. https://github.com/php/php-src/blob/9d7e03c325473024e54c864f0379efc1bbf03e72/ext/ffi/ffi.c#L1990 it's easy to reproduct with the same structs used here: https://github.com/php/php-src/commit/05f3cd23ed61d800a861f2dd057ed56e783ea6f1#diff-3ea95b4dc57e34c882215bcc36f84551 i am not sure if this is a bug or a very consusing api limitation related to the livetime of zvals. Test script: --------------- // php code that SEGFAULTS function ffi() { return \FFI::cdef( file_get_contents(__DIR__ . '/example.h'), __DIR__ . '/lib.so' ); } $res = ffi()->bug79096(); var_dump($res); // php code that WORKS // same as above $ffi = ffi(); $res = $ffi->bug79096(); // c code struct bug79096 bug79096(void) { struct bug79096 b; b.a = 1; b.b = 1; return b; } // header struct bug79096 { uint64_t a; uint64_t b; }; struct bug79096 bug79096(void); Expected result: ---------------- object(FFI\CData:struct bug79096)#9 (2) { ["a"]=> int(1) ["b"]=> int(1) } -- Edit bug report at https://bugs.php.net/bug.php?id=79125&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79125&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79125&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79125&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79125&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79125&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79125&r=support Expected behavior: https://bugs.php.net/fix.php?id=79125&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79125&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79125&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79125&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79125&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79125&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79125&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79125&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79125&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79125&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79125&r=mysqlcfg

« previous php.bugs (#224923) next »