|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80186 Segfault when iterating over FFI object
Submitted: 2020-10-04 20:40 UTC Modified: 2020-10-04 20:56 UTC
From: Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 8.0Git-2020-10-04 (Git) OS:
Private report: No CVE-ID: None
 [2020-10-04 20:40 UTC]
Currently `zend_fake_get_properties` in `ext/ffi/ffi.c` returns a pointer to const HashTable `zend_empty_array`. Attempting to iterate over this array in userland leads to a segfault because PHP tries to increment `zend_empty_array`'s `nIteratorsCount` which is const memory.

The proposed patch allows objects to return NULL for the `get_properties` handler. In this case, the VM skips the foreach block.

If this approach is acceptable, there are other extensions and call sites[1][2] to fix where `zend_empty_array` leaks into userland.


Test script:

$ffi = FFI::cdef('');

foreach ($ffi as $_) {

Expected result:
no segfault

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-04 20:56 UTC]
The following pull request has been associated:

Patch Name: Fix #80186: Prevent segfault when iterating FFI obj props
On GitHub:
 [2020-10-04 20:56 UTC]
zend_empty_array is also used for normal empty arrays [], so it should be possible to make this work...
 [2020-10-09 15:03 UTC]
Automatic comment on behalf of
Log: Fixed bug #80186
 [2020-10-09 15:03 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 22:01:29 2024 UTC