Skip to content
Closed
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
6 changes: 5 additions & 1 deletion ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3255,7 +3255,11 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */

code_size = buf.st_size;
code = emalloc(code_size + 1);
fd = open(filename, O_RDONLY, 0);
int open_flags = O_RDONLY;
#ifdef PHP_WIN32
open_flags |= _O_BINARY;
#endif
fd = open(filename, open_flags, 0);
if (fd < 0 || read(fd, code, code_size) != code_size) {
if (preload) {
zend_error(E_WARNING, "FFI: Failed pre-loading '%s', cannot read_file", filename);
Expand Down
3 changes: 3 additions & 0 deletions ext/ffi/tests/gh14215.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define FFI_LIB "Kernel32.dll"
typedef unsigned long DWORD;
DWORD GetLastError(void);
23 changes: 23 additions & 0 deletions ext/ffi/tests/gh14215.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-14215 (Cannot use FFI::load on CRLF header file with apache2handler)
--EXTENSIONS--
ffi
zend_test
--SKIPIF--
<?php
if(PHP_OS_FAMILY !== "Windows") {
die('skip only for Windows');
}
?>
--INI--
ffi.enable=1
--FILE--
<?php
zend_test_set_fmode(false);
$header_path = __DIR__.'\\gh14215.h';
$ffi = FFI::load($header_path);
var_dump($ffi->GetLastError());
zend_test_set_fmode(true);
?>
--EXPECT--
int(0)
12 changes: 12 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,18 @@ static ZEND_FUNCTION(zend_test_is_pcre_bundled)
#endif
}

#ifdef PHP_WIN32
static ZEND_FUNCTION(zend_test_set_fmode)
{
bool binary;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_BOOL(binary)
ZEND_PARSE_PARAMETERS_END();

_fmode = binary ? _O_BINARY : _O_TEXT;
}
#endif

static zend_object *zend_test_class_new(zend_class_entry *class_type)
{
zend_object *obj = zend_objects_new(class_type);
Expand Down
4 changes: 4 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ function zend_test_override_libxml_global_state(): void {}
#endif

function zend_test_is_pcre_bundled(): bool {}

#if defined(PHP_WIN32)
function zend_test_set_fmode(bool $binary): void {}
#endif
}

namespace ZendTestNS {
Expand Down
14 changes: 13 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.