From a1f5c8a587ff6dfa309ccf34c1508a8977e77f82 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 16 Aug 2022 13:34:14 +0200 Subject: [PATCH] Fix GH-9227: Trailing dots and spaces in filenames are ignored Given that Windows ignores trailing dots and spaces in filenames, we catch that ourselves to avoid confusion with the respective filenames without these characters. Closes GH-9229. --- NEWS | 2 ++ Zend/zend_virtual_cwd.c | 7 ++++ .../SplFileInfo_getExtension_basic-win32.phpt | 33 +++++++++++++++++++ .../tests/SplFileInfo_getExtension_basic.phpt | 4 +++ ext/standard/tests/file/gh9227.phpt | 20 +++++++++++ 5 files changed, 66 insertions(+) create mode 100644 ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt create mode 100644 ext/standard/tests/file/gh9227.phpt diff --git a/NEWS b/NEWS index 3b72ca44b51..e2851b4878d 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug GH-9323 (Crash in ZEND_RETURN/GC/zend_call_function) (Tim Starling) + . Fixed bug GH-9227 (Trailing dots and spaces in filenames are ignored). + (cmb) - DOM: . Fixed bug #79451 (Using DOMDocument->replaceChild on doctype causes diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 14e55fab447..64fc1651740 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -603,6 +603,7 @@ retry_reparse_point: if (!pathw) { return (size_t)-1; } + PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, (size_t)-1, 1); hFind = FindFirstFileExW(pathw, FindExInfoBasic, &dataw, FindExSearchNameMatch, NULL, 0); if (INVALID_HANDLE_VALUE == hFind) { if (use_realpath == CWD_REALPATH) { @@ -1139,7 +1140,13 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL); if (path_length == (size_t)-1) { +#ifdef ZEND_WIN32 + if (errno != EACCES) { + errno = ENOENT; + } +#else errno = ENOENT; +#endif return 1; } diff --git a/ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt b/ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt new file mode 100644 index 00000000000..5b1e2ed8ad8 --- /dev/null +++ b/ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL: SplFileInfo::getExtension() basic test +--SKIPIF-- + +--FILE-- +getExtension(), pathinfo($file . $ext, PATHINFO_EXTENSION)); +} +?> +--CLEAN-- + +--EXPECT-- +string(3) "txt" +string(3) "txt" +string(9) "extension" +string(9) "extension" +string(0) "" +string(0) "" +string(0) "" +string(0) "" diff --git a/ext/spl/tests/SplFileInfo_getExtension_basic.phpt b/ext/spl/tests/SplFileInfo_getExtension_basic.phpt index 370257495b8..c75e0ed48ff 100644 --- a/ext/spl/tests/SplFileInfo_getExtension_basic.phpt +++ b/ext/spl/tests/SplFileInfo_getExtension_basic.phpt @@ -1,5 +1,9 @@ --TEST-- SPL: SplFileInfo::getExtension() basic test +--SKIPIF-- + --FILE-- +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(false) +int(3) +bool(false)