From 34963459cd8cf46a4ebfe4e01f315ed8bd71a01c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 9 Aug 2019 11:04:21 +0200 Subject: [PATCH 1/2] Fix #78386: fstat mode has unexpected value on PHP 7.4 We must not assume that any file which is not a directory is a regular file. Therefore we employ `GetFileType()` in this case to properly distinguish between character special, FIFO special and regular files. --- ext/standard/tests/file/bug78386.phpt | 10 ++++++++++ win32/ioutil.c | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/file/bug78386.phpt diff --git a/ext/standard/tests/file/bug78386.phpt b/ext/standard/tests/file/bug78386.phpt new file mode 100644 index 0000000000000..e7a723e92e899 --- /dev/null +++ b/ext/standard/tests/file/bug78386.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #78386 (fstat mode has unexpected value on PHP 7.4) +--FILE-- + +--EXPECT-- +string(5) "10666" diff --git a/win32/ioutil.c b/win32/ioutil.c index 669876da38548..f7db410dd2f50 100644 --- a/win32/ioutil.c +++ b/win32/ioutil.c @@ -942,7 +942,20 @@ static int php_win32_ioutil_fstat_int(HANDLE h, php_win32_ioutil_stat_t *buf, co } if ((data->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) { - buf->st_mode |= is_dir ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG; + if (is_dir) { + buf->st_mode |= (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)); + } else { + switch (GetFileType(h)) { + case FILE_TYPE_CHAR: + buf->st_mode |= S_IFCHR; + break; + case FILE_TYPE_PIPE: + buf->st_mode |= S_IFIFO; + break; + default: + buf->st_mode |= S_IFREG; + } + } buf->st_mode |= (data->dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6)); } From 70ff1f4830ff4ef8d641042e34df5ca7ea274b55 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 9 Aug 2019 11:46:42 +0200 Subject: [PATCH 2/2] Test is for Windows only --- ext/standard/tests/file/bug78386.phpt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/standard/tests/file/bug78386.phpt b/ext/standard/tests/file/bug78386.phpt index e7a723e92e899..9118761aab21c 100644 --- a/ext/standard/tests/file/bug78386.phpt +++ b/ext/standard/tests/file/bug78386.phpt @@ -1,5 +1,9 @@ --TEST-- Bug #78386 (fstat mode has unexpected value on PHP 7.4) +--SKIPIF-- + --FILE--