Skip to content

Commit 0e98a05

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

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
@@ -3282,7 +3282,11 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
32823282

32833283
code_size = buf.st_size;
32843284
code = emalloc(code_size + 1);
3285-
fd = open(filename, O_RDONLY, 0);
3285+
int open_flags = O_RDONLY;
3286+
#ifdef PHP_WIN32
3287+
open_flags |= _O_BINARY;
3288+
#endif
3289+
fd = open(filename, open_flags, 0);
32863290
if (fd < 0 || read(fd, code, code_size) != code_size) {
32873291
if (preload) {
32883292
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
@@ -738,6 +738,18 @@ static ZEND_FUNCTION(zend_test_is_pcre_bundled)
738738
#endif
739739
}
740740

741+
#ifdef PHP_WIN32
742+
static ZEND_FUNCTION(zend_test_set_fmode)
743+
{
744+
bool binary;
745+
ZEND_PARSE_PARAMETERS_START(1, 1)
746+
Z_PARAM_BOOL(binary)
747+
ZEND_PARSE_PARAMETERS_END();
748+
749+
_fmode = binary ? _O_BINARY : _O_TEXT;
750+
}
751+
#endif
752+
741753
static zend_object *zend_test_class_new(zend_class_entry *class_type)
742754
{
743755
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
@@ -246,6 +246,10 @@ function zend_test_override_libxml_global_state(): void {}
246246
#endif
247247

248248
function zend_test_is_pcre_bundled(): bool {}
249+
250+
#if defined(PHP_WIN32)
251+
function zend_test_set_fmode(bool $binary): void {}
252+
#endif
249253
}
250254

251255
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)