Skip to content

Fix GH-16397: Segmentation fault when comparing FFI object #16401

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

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ PHP NEWS
. Fixed bug GH-16409 (Segfault in exif_thumbnail when not dealing with a
real file). (nielsdos, cmb)

- FFI:
. Fixed bug GH-16397 (Segmentation fault when comparing FFI object).
(nielsdos)

- GD:
. Fixed bug GH-16334 (imageaffine overflow on matrix elements).
(David Carlier)
Expand Down
8 changes: 7 additions & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2922,6 +2922,12 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
}
/* }}} */

static int zend_fake_compare_objects(zval *o1, zval *o2)
{
zend_throw_error(zend_ffi_exception_ce, "Cannot compare FFI objects");
return ZEND_UNCOMPARABLE;
}

static zend_never_inline int zend_ffi_disabled(void) /* {{{ */
{
zend_throw_error(zend_ffi_exception_ce, "FFI API is restricted by \"ffi.enable\" configuration directive");
Expand Down Expand Up @@ -5367,7 +5373,7 @@ ZEND_MINIT_FUNCTION(ffi)
zend_ffi_handlers.has_dimension = zend_fake_has_dimension;
zend_ffi_handlers.unset_dimension = zend_fake_unset_dimension;
zend_ffi_handlers.get_method = zend_ffi_get_func;
zend_ffi_handlers.compare = NULL;
zend_ffi_handlers.compare = zend_fake_compare_objects;
zend_ffi_handlers.cast_object = zend_fake_cast_object;
zend_ffi_handlers.get_debug_info = NULL;
zend_ffi_handlers.get_closure = NULL;
Expand Down
15 changes: 15 additions & 0 deletions ext/ffi/tests/gh16397.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-16397 (Segmentation fault when comparing FFI object)
--EXTENSIONS--
ffi
--FILE--
<?php
$ffi = FFI::cdef();
try {
var_dump($ffi != 1);
} catch (FFI\Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot compare FFI objects
Loading