Skip to content

PHP bypass Rust destructors when zend_bailout #537

@ptondereau

Description

@ptondereau

Description

From discord discussion:

_emalloc will call zend_bailout should PHP's memory limit be reached. In the background, this will do a long jump bypassing any Rust destructors (effectively not freeing memory).

We would simply end up intercepting the bailout (like here: https://gist.github.com/awons/d87db73d1ad5eae1445b9de7e3727c6a) and then panicking. But that panic needs to be caught before it crosses the FFI boundary. And then, in C we would need to again bail to make sure the OOM works as it should.

Long jump located here

Steps to Reproduce

https://github.com/ptondereau/php-rust-bailout-repro

Affected Components

  • ext-php-rs
  • macros
  • cli (cargo-php)

PHP Version

Every PHP version

ext-php-rs Version

every

Operating System

every

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions