Skip to content

Commit 53fc8ef

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Disable instantiation of zero size FFI\CData objects Fix # 79171: heap-buffer-overflow in phar_extract_file Fix bug #79082 - Files added to tar with Phar::buildFromIterator have all-access permissions Fix bug #79221 - Null Pointer Dereference in PHP Session Upload Progress
2 parents cf8407a + 54ecf57 commit 53fc8ef

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

ext/ffi/ffi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,6 +3657,12 @@ ZEND_METHOD(FFI, new) /* {{{ */
36573657
}
36583658
}
36593659

3660+
if (type->size == 0) {
3661+
zend_throw_error(zend_ffi_exception_ce, "Cannot instantiate FFI\\CData of zero size");
3662+
zend_ffi_type_dtor(type_ptr);
3663+
return;
3664+
}
3665+
36603666
ptr = pemalloc(type->size, flags & ZEND_FFI_FLAG_PERSISTENT);
36613667
memset(ptr, 0, type->size);
36623668

ext/ffi/tests/023.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ FFI 023: GCC struct extensions
66
ffi.enable=1
77
--FILE--
88
<?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+
}
1014
var_dump(FFI::sizeof(FFI::new("struct {int a}")));
1115
var_dump(FFI::sizeof(FFI::new("struct {int a; int b}")));
1216
?>
1317
ok
1418
--EXPECT--
15-
int(0)
19+
FFI\Exception: Cannot instantiate FFI\CData of zero size
1620
int(4)
1721
int(8)
1822
ok

ext/ffi/tests/027.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ FFI\ParserException: '[*]' not allowed in other than function prototype scope at
8181
FFI\ParserException: '[*]' not allowed in other than function prototype scope at line 1
8282
FFI\ParserException: '[*]' not allowed in other than function prototype scope at line 1
8383
ok
84-
int(0)
84+
FFI\Exception: Cannot instantiate FFI\CData of zero size
8585
FFI\ParserException: '[]' not allowed at line 1
8686
FFI\ParserException: '[]' not allowed at line 1
8787
ok

ext/ffi/tests/045.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ try {
2424
bool(true)
2525
bool(false)
2626
TypeError: FFI::isNull() expects parameter 1 to be FFI\CData, null given
27-
FFI\Exception: FFI\Cdata is not a pointer
27+
FFI\Exception: Cannot instantiate FFI\CData of zero size

0 commit comments

Comments
 (0)