Skip to content

Commit 889f308

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-14215: Cannot use FFI::load on CRLF header file with apache2handler
2 parents c8920aa + 0e98a05 commit 889f308

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

ext/ffi/ffi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3283,7 +3283,11 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
32833283

32843284
code_size = buf.st_size;
32853285
code = emalloc(code_size + 1);
3286-
fd = open(filename, O_RDONLY, 0);
3286+
int open_flags = O_RDONLY;
3287+
#ifdef PHP_WIN32
3288+
open_flags |= _O_BINARY;
3289+
#endif
3290+
fd = open(filename, open_flags, 0);
32873291
if (fd < 0 || read(fd, code, code_size) != code_size) {
32883292
if (preload) {
32893293
zend_error(E_WARNING, "FFI: Failed pre-loading '%s', cannot read_file", filename);

ext/ffi/tests/gh14215.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define FFI_LIB "Kernel32.dll"
2+
typedef unsigned long DWORD;
3+
DWORD GetLastError(void);

ext/ffi/tests/gh14215.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-14215 (Cannot use FFI::load on CRLF header file with apache2handler)
3+
--EXTENSIONS--
4+
ffi
5+
zend_test
6+
--SKIPIF--
7+
<?php
8+
if(PHP_OS_FAMILY !== "Windows") {
9+
die('skip only for Windows');
10+
}
11+
?>
12+
--INI--
13+
ffi.enable=1
14+
--FILE--
15+
<?php
16+
zend_test_set_fmode(false);
17+
$header_path = __DIR__.'\\gh14215.h';
18+
$ffi = FFI::load($header_path);
19+
var_dump($ffi->GetLastError());
20+
zend_test_set_fmode(true);
21+
?>
22+
--EXPECT--
23+
int(0)

ext/zend_test/test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,18 @@ static ZEND_FUNCTION(zend_test_is_pcre_bundled)
739739
#endif
740740
}
741741

742+
#ifdef PHP_WIN32
743+
static ZEND_FUNCTION(zend_test_set_fmode)
744+
{
745+
bool binary;
746+
ZEND_PARSE_PARAMETERS_START(1, 1)
747+
Z_PARAM_BOOL(binary)
748+
ZEND_PARSE_PARAMETERS_END();
749+
750+
_fmode = binary ? _O_BINARY : _O_TEXT;
751+
}
752+
#endif
753+
742754
static zend_object *zend_test_class_new(zend_class_entry *class_type)
743755
{
744756
zend_object *obj = zend_objects_new(class_type);

ext/zend_test/test.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ function zend_test_override_libxml_global_state(): void {}
275275
#endif
276276

277277
function zend_test_is_pcre_bundled(): bool {}
278+
279+
#if defined(PHP_WIN32)
280+
function zend_test_set_fmode(bool $binary): void {}
281+
#endif
278282
}
279283

280284
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)