Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when comparing FFI object #16397

Closed
YuanchengJiang opened this issue Oct 12, 2024 · 2 comments · Fixed by #16401
Closed

Segmentation fault when comparing FFI object #16397

YuanchengJiang opened this issue Oct 12, 2024 · 2 comments · Fixed by #16401

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$ffi = FFI::scope("TEST_300");
$ffi->printf("Hello World from %s!\n", "PHP");
$fusion = $ffi;
var_dump($fusion != 1);
?>

Resulted in this output:

Segmentation fault (core dumped)

To reproduce:

-d "zend_extension=/php-src/modules/opcache.so" -d "ffi.enable=1" -d "opcache.enable=1" -d "opcache.enable_cli=1" -d "opcache.preload=/php-src/tests/fused/preload.inc"

PHP Version

nightly

Operating System

ubuntu 22.04

@nielsdos
Copy link
Member

Much simpler reproducer that doesn't need opcache:

<?php
$ffi = FFI::cdef();
var_dump($ffi != 1);

@nielsdos
Copy link
Member

The problem is that the compare handler is required according to https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64, but it isn't set for FFI. Should probably return ZEND_UNCOMPARABLE. I'll think a bit.

@nielsdos nielsdos changed the title Segmentation fault when comparing FFI object with constant Segmentation fault when comparing FFI object Oct 12, 2024
nielsdos added a commit to nielsdos/php-src that referenced this issue Oct 12, 2024
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64
@nielsdos nielsdos linked a pull request Oct 12, 2024 that will close this issue
nielsdos added a commit to nielsdos/php-src that referenced this issue Oct 14, 2024
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64

Closes phpGH-16401.
nielsdos added a commit to nielsdos/php-src that referenced this issue Oct 14, 2024
`compare` is a required handler [1], but this handler was set to NULL.
Throw an exception when trying to compare FFI objects.

[1] https://github.com/php/php-src/blob/35c8a010c6633a2a1ba7c16a0cf83affa07b819e/Zend/zend_object_handlers.h#L231C1-L231C64

Closes phpGH-16401.
nielsdos added a commit that referenced this issue Oct 14, 2024
* PHP-8.2:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
nielsdos added a commit that referenced this issue Oct 14, 2024
* PHP-8.3:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
nielsdos added a commit that referenced this issue Oct 14, 2024
* PHP-8.4:
  Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants