File tree Expand file tree Collapse file tree 4 files changed +14
-4
lines changed Expand file tree Collapse file tree 4 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -3685,6 +3685,12 @@ ZEND_METHOD(FFI, new) /* {{{ */
3685
3685
}
3686
3686
}
3687
3687
3688
+ if (type -> size == 0 ) {
3689
+ zend_throw_error (zend_ffi_exception_ce , "Cannot instantiate FFI\\CData of zero size" );
3690
+ zend_ffi_type_dtor (type_ptr );
3691
+ return ;
3692
+ }
3693
+
3688
3694
ptr = pemalloc (type -> size , flags & ZEND_FFI_FLAG_PERSISTENT );
3689
3695
memset (ptr , 0 , type -> size );
3690
3696
Original file line number Diff line number Diff line change @@ -6,13 +6,17 @@ FFI 023: GCC struct extensions
6
6
ffi.enable=1
7
7
--FILE--
8
8
<?php
9
- var_dump (FFI ::sizeof (FFI ::new ("struct {} " )));
9
+ try {
10
+ var_dump (FFI ::sizeof (FFI ::new ("struct {} " )));
11
+ } catch (Throwable $ e ) {
12
+ echo get_class ($ e ) . ": " . $ e ->getMessage () . "\n" ;
13
+ }
10
14
var_dump (FFI ::sizeof (FFI ::new ("struct {int a} " )));
11
15
var_dump (FFI ::sizeof (FFI ::new ("struct {int a; int b} " )));
12
16
?>
13
17
ok
14
18
--EXPECT--
15
- int(0)
19
+ FFI\Exception: Cannot instantiate FFI\CData of zero size
16
20
int(4)
17
21
int(8)
18
22
ok
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ FFI\ParserException: '[*]' not allowed in other than function prototype scope at
81
81
FFI\ParserException: '[*]' not allowed in other than function prototype scope at line 1
82
82
FFI\ParserException: '[*]' not allowed in other than function prototype scope at line 1
83
83
ok
84
- int(0)
84
+ FFI\Exception: Cannot instantiate FFI\CData of zero size
85
85
FFI\ParserException: '[]' not allowed at line 1
86
86
FFI\ParserException: '[]' not allowed at line 1
87
87
ok
Original file line number Diff line number Diff line change @@ -26,4 +26,4 @@ bool(false)
26
26
27
27
Warning: FFI::isNull() expects parameter 1 to be FFI\CData, null given in %s045.php on line %d
28
28
NULL
29
- FFI\Exception: FFI\Cdata is not a pointer
29
+ FFI\Exception: Cannot instantiate FFI\CData of zero size
You can’t perform that action at this time.
0 commit comments