Skip to content

Commit 7a7ab73

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16397: Segmentation fault when comparing FFI object (#16401)
2 parents 253f4af + c924af0 commit 7a7ab73

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ PHP NEWS
3030
. Fixed bug GH-16409 (Segfault in exif_thumbnail when not dealing with a
3131
real file). (nielsdos, cmb)
3232

33+
- FFI:
34+
. Fixed bug GH-16397 (Segmentation fault when comparing FFI object).
35+
(nielsdos)
36+
3337
- GD:
3438
. Fixed bug GH-16334 (imageaffine overflow on matrix elements).
3539
(David Carlier)

ext/ffi/ffi.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,12 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
29382938
}
29392939
/* }}} */
29402940

2941+
static int zend_fake_compare_objects(zval *o1, zval *o2)
2942+
{
2943+
zend_throw_error(zend_ffi_exception_ce, "Cannot compare FFI objects");
2944+
return ZEND_UNCOMPARABLE;
2945+
}
2946+
29412947
static zend_never_inline int zend_ffi_disabled(void) /* {{{ */
29422948
{
29432949
zend_throw_error(zend_ffi_exception_ce, "FFI API is restricted by \"ffi.enable\" configuration directive");
@@ -5443,7 +5449,7 @@ ZEND_MINIT_FUNCTION(ffi)
54435449
zend_ffi_handlers.has_dimension = zend_fake_has_dimension;
54445450
zend_ffi_handlers.unset_dimension = zend_fake_unset_dimension;
54455451
zend_ffi_handlers.get_method = zend_ffi_get_func;
5446-
zend_ffi_handlers.compare = NULL;
5452+
zend_ffi_handlers.compare = zend_fake_compare_objects;
54475453
zend_ffi_handlers.cast_object = zend_fake_cast_object;
54485454
zend_ffi_handlers.get_debug_info = NULL;
54495455
zend_ffi_handlers.get_closure = NULL;

ext/ffi/tests/gh16397.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-16397 (Segmentation fault when comparing FFI object)
3+
--EXTENSIONS--
4+
ffi
5+
--FILE--
6+
<?php
7+
$ffi = FFI::cdef();
8+
try {
9+
var_dump($ffi != 1);
10+
} catch (FFI\Exception $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
?>
14+
--EXPECT--
15+
Cannot compare FFI objects

0 commit comments

Comments
 (0)