|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79125 FFI lifetime
Submitted: 2020-01-15 19:11 UTC Modified: 2021-09-16 21:31 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at tim dot ainfach dot de Assigned:
Status: Verified Package: FFI (PECL)
PHP Version: 7.4.2RC1 OS: OSX 10.14.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at tim dot ainfach dot de
New email:
PHP Version: OS:


 [2020-01-15 19:11 UTC] php at tim dot ainfach dot de
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.

it's easy to reproduct with the same structs used here:

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__ . '/'

$res = ffi()->bug79096();

// 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) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-15 19:27 UTC] php at tim dot ainfach dot de
-Summary: FFI Struct Segfault +Summary: FFI lifetime
 [2020-01-15 19:27 UTC] php at tim dot ainfach dot de
sorry for the misleading title, seems that i cant change it? "FFI lifetime" would be much better.
 [2020-01-16 11:51 UTC]
-Status: Open +Status: Verified
 [2020-01-16 11:51 UTC]
Indeed, after `::bug79096()` has been called, the FFI instance is
destroyed including all its types, although the FFI\Cdata instance
still holds a pointer to the `struct bug79096` type.  This results
in a use-after-free.
 [2021-09-16 21:31 UTC]
-Package: *Extensibility Functions +Package: FFI
 [2023-06-21 10:13 UTC] ph dot anthanhhaikdb33 at gmail dot com
Thanks for the information...
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC