|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78761 Zend memory heap corruption with preload and pointer casting
Submitted: 2019-10-30 11:28 UTC Modified: 2019-10-30 18:02 UTC
From: lisachenko dot it at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *Extensibility Functions
PHP Version: 7.4.0RC4 OS: Windows x64
Private report: No CVE-ID: None
 [2019-10-30 11:28 UTC] lisachenko dot it at gmail dot com
There is a zend_mm_heap corruption when using FFI preload mode and proxying requests to the FFI::cast from a preloaded class.
Corruptions appear when trying to cast any CData pointer to another type via preloaded class that wraps FFI::cast() internally.

Test script:
See gist:

Expected result:
No memory corruption

Actual result:
Script terminated with zend_mm_heap corrupted


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-30 17:52 UTC]
-Status: Open +Status: Verified
 [2019-10-30 17:52 UTC]
I can confirm this issue.  Simpler reproducer:

    FFI::cast('char[10]', FFI::new('char[1]'));

and opcache.preload=preload.php which is

    FFI::load(__DIR__ . '/header.h');

header.h may be empty.

The immediate problem seems to be that preloading sets
FFI_G(persistent) to 1, but doesn't necessarily reset it to 0 when
the loading is finished.  This causes the array type to be
allocated persistently, but it is later freed with efree().
 [2019-10-30 18:02 UTC]
-Assigned To: +Assigned To: cmb
 [2019-10-30 18:06 UTC]
The following pull request has been associated:

Patch Name: Fix #78761: Zend memory heap corruption with preload and casting
On GitHub:
 [2019-10-30 18:50 UTC]
Automatic comment on behalf of
Log: Fix #78761: Zend memory heap corruption with preload and casting
 [2019-10-30 18:50 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 18:01:28 2024 UTC