2000-09-04 02:18:13 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 17:03:12 +08:00
|
|
|
| Copyright (c) The PHP Group |
|
2000-09-04 02:18:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2000-09-04 02:18:13 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-25 13:05:06 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2021-05-06 18:16:35 +08:00
|
|
|
| https://www.php.net/license/3_01.txt |
|
2000-09-04 02:18:13 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2018-11-01 23:20:07 +08:00
|
|
|
| Authors: Andi Gutmans <andi@php.net> |
|
2000-09-04 02:18:13 +08:00
|
|
|
| Sascha Schumann <sascha@schumann.cx> |
|
2010-09-01 17:49:53 +08:00
|
|
|
| Pierre Joye <pierre@php.net> |
|
2000-09-04 02:18:13 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VIRTUAL_CWD_H
|
|
|
|
#define VIRTUAL_CWD_H
|
|
|
|
|
2001-08-05 09:34:40 +08:00
|
|
|
#include "TSRM.h"
|
2000-09-04 02:58:46 +08:00
|
|
|
|
2000-09-04 02:18:13 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_UTIME_H
|
|
|
|
#include <utime.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2019-07-12 08:57:52 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2024-06-09 20:23:41 +08:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2019-07-12 08:57:52 +08:00
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAXPATHLEN
|
2024-06-09 20:23:41 +08:00
|
|
|
# ifdef _WIN32
|
2019-07-12 08:57:52 +08:00
|
|
|
# include "win32/ioutil.h"
|
|
|
|
# define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
|
|
|
|
# elif PATH_MAX
|
|
|
|
# define MAXPATHLEN PATH_MAX
|
|
|
|
# elif defined(MAX_PATH)
|
|
|
|
# define MAXPATHLEN MAX_PATH
|
|
|
|
# else
|
|
|
|
# define MAXPATHLEN 256
|
|
|
|
# endif
|
|
|
|
#endif
|
2000-09-04 02:18:13 +08:00
|
|
|
|
2006-09-04 16:18:15 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
#define VIRTUAL_DIR
|
|
|
|
#endif
|
|
|
|
|
2015-07-05 00:55:22 +08:00
|
|
|
#ifndef ZEND_WIN32
|
2000-09-04 02:18:13 +08:00
|
|
|
#include <unistd.h>
|
2006-09-04 16:18:15 +08:00
|
|
|
#else
|
|
|
|
#include <direct.h>
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif
|
|
|
|
|
2003-08-07 23:32:18 +08:00
|
|
|
#if defined(__osf__) || defined(_AIX)
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
|
2024-05-21 04:30:38 +08:00
|
|
|
#include "zend_stream.h"
|
|
|
|
|
2015-07-05 00:55:22 +08:00
|
|
|
#ifdef ZEND_WIN32
|
2019-04-28 11:15:47 +08:00
|
|
|
#include "win32/readdir.h"
|
2000-09-04 12:18:38 +08:00
|
|
|
#include <sys/utime.h>
|
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
|
|
|
#include "win32/ioutil.h"
|
2000-09-04 02:47:35 +08:00
|
|
|
/* mode_t isn't defined on Windows */
|
2000-11-01 02:05:28 +08:00
|
|
|
typedef unsigned short mode_t;
|
2000-09-04 02:18:13 +08:00
|
|
|
|
2000-10-04 00:36:32 +08:00
|
|
|
#define DEFAULT_SLASH '\\'
|
2001-07-16 21:31:22 +08:00
|
|
|
#define DEFAULT_DIR_SEPARATOR ';'
|
2000-09-04 02:18:13 +08:00
|
|
|
#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
|
2002-04-25 22:43:40 +08:00
|
|
|
#define IS_SLASH_P(c) (*(c) == '/' || \
|
|
|
|
(*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
|
2002-11-05 04:45:28 +08:00
|
|
|
|
2003-06-25 13:05:06 +08:00
|
|
|
/* COPY_WHEN_ABSOLUTE is 2 under Win32 because by chance both regular absolute paths
|
|
|
|
in the file system and UNC paths need copying of two characters */
|
2002-11-05 04:45:28 +08:00
|
|
|
#define COPY_WHEN_ABSOLUTE(path) 2
|
2001-03-23 16:33:06 +08:00
|
|
|
#define IS_UNC_PATH(path, len) \
|
|
|
|
(len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1]))
|
2003-06-25 13:05:06 +08:00
|
|
|
#define IS_ABSOLUTE_PATH(path, len) \
|
2014-10-02 19:50:46 +08:00
|
|
|
(len >= 2 && (/* is local */isalpha(path[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
|
2000-09-04 02:18:13 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
2023-07-02 20:35:43 +08:00
|
|
|
|
|
|
|
#ifndef DT_UNKNOWN
|
|
|
|
# define DT_UNKNOWN 0
|
|
|
|
#endif
|
|
|
|
#ifndef DT_DIR
|
|
|
|
# define DT_DIR 4
|
|
|
|
#endif
|
|
|
|
#ifndef DT_REG
|
|
|
|
# define DT_REG 8
|
|
|
|
#endif
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif
|
|
|
|
|
2000-10-04 00:36:32 +08:00
|
|
|
#define DEFAULT_SLASH '/'
|
2001-11-03 21:33:21 +08:00
|
|
|
|
|
|
|
#ifdef __riscos__
|
|
|
|
#define DEFAULT_DIR_SEPARATOR ';'
|
|
|
|
#else
|
|
|
|
#define DEFAULT_DIR_SEPARATOR ':'
|
|
|
|
#endif
|
|
|
|
|
2000-09-04 02:18:13 +08:00
|
|
|
#define IS_SLASH(c) ((c) == '/')
|
2002-04-25 22:43:40 +08:00
|
|
|
#define IS_SLASH_P(c) (*(c) == '/')
|
2000-09-04 02:18:13 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-10-04 00:36:32 +08:00
|
|
|
|
|
|
|
#ifndef COPY_WHEN_ABSOLUTE
|
2002-11-05 04:45:28 +08:00
|
|
|
#define COPY_WHEN_ABSOLUTE(path) 0
|
2000-10-04 00:36:32 +08:00
|
|
|
#endif
|
|
|
|
|
2010-09-13 17:08:42 +08:00
|
|
|
#ifndef IS_ABSOLUTE_PATH
|
2000-09-04 02:18:13 +08:00
|
|
|
#define IS_ABSOLUTE_PATH(path, len) \
|
|
|
|
(IS_SLASH(path[0]))
|
|
|
|
#endif
|
|
|
|
|
2000-09-04 02:47:35 +08:00
|
|
|
#ifdef TSRM_EXPORTS
|
2000-09-04 02:18:13 +08:00
|
|
|
#define CWD_EXPORTS
|
|
|
|
#endif
|
|
|
|
|
2015-07-05 00:55:22 +08:00
|
|
|
#ifdef ZEND_WIN32
|
2008-01-30 17:41:12 +08:00
|
|
|
# ifdef CWD_EXPORTS
|
|
|
|
# define CWD_API __declspec(dllexport)
|
|
|
|
# else
|
|
|
|
# define CWD_API __declspec(dllimport)
|
|
|
|
# endif
|
|
|
|
#elif defined(__GNUC__) && __GNUC__ >= 4
|
|
|
|
# define CWD_API __attribute__ ((visibility("default")))
|
2000-09-04 02:18:13 +08:00
|
|
|
#else
|
2008-01-30 17:41:12 +08:00
|
|
|
# define CWD_API
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif
|
|
|
|
|
2015-07-05 00:55:22 +08:00
|
|
|
#ifdef ZEND_WIN32
|
2018-07-15 15:33:14 +08:00
|
|
|
# define php_sys_stat_ex php_win32_ioutil_stat_ex
|
|
|
|
# define php_sys_stat php_win32_ioutil_stat
|
|
|
|
# define php_sys_lstat php_win32_ioutil_lstat
|
|
|
|
# define php_sys_fstat php_win32_ioutil_fstat
|
2018-10-04 00:56:08 +08:00
|
|
|
# define php_sys_readlink php_win32_ioutil_readlink
|
2018-08-02 20:08:30 +08:00
|
|
|
# define php_sys_symlink php_win32_ioutil_symlink
|
|
|
|
# define php_sys_link php_win32_ioutil_link
|
2006-11-10 23:04:07 +08:00
|
|
|
#else
|
|
|
|
# define php_sys_stat stat
|
2010-09-01 17:49:53 +08:00
|
|
|
# define php_sys_lstat lstat
|
2018-07-15 15:33:14 +08:00
|
|
|
# define php_sys_fstat fstat
|
2010-09-10 22:01:44 +08:00
|
|
|
# ifdef HAVE_SYMLINK
|
|
|
|
# define php_sys_readlink(link, target, target_len) readlink(link, target, target_len)
|
2018-08-02 20:08:30 +08:00
|
|
|
# define php_sys_symlink symlink
|
|
|
|
# define php_sys_link link
|
2010-09-10 22:01:44 +08:00
|
|
|
# endif
|
2006-11-10 23:04:07 +08:00
|
|
|
#endif
|
|
|
|
|
2000-09-04 02:18:13 +08:00
|
|
|
typedef struct _cwd_state {
|
|
|
|
char *cwd;
|
2017-07-27 05:10:07 +08:00
|
|
|
size_t cwd_length;
|
2000-09-04 02:18:13 +08:00
|
|
|
} cwd_state;
|
|
|
|
|
|
|
|
typedef int (*verify_path_func)(const cwd_state *);
|
|
|
|
|
|
|
|
CWD_API void virtual_cwd_startup(void);
|
|
|
|
CWD_API void virtual_cwd_shutdown(void);
|
2024-08-23 22:28:37 +08:00
|
|
|
CWD_API void virtual_cwd_activate(void);
|
|
|
|
CWD_API void virtual_cwd_deactivate(void);
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API char *virtual_getcwd_ex(size_t *length);
|
|
|
|
CWD_API char *virtual_getcwd(char *buf, size_t size);
|
2023-04-19 22:59:20 +08:00
|
|
|
CWD_API zend_result virtual_chdir(const char *path);
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path));
|
|
|
|
CWD_API int virtual_filepath(const char *path, char **filepath);
|
|
|
|
CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_func verify_path);
|
|
|
|
CWD_API char *virtual_realpath(const char *path, char *real_path);
|
|
|
|
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
|
|
|
|
CWD_API int virtual_open(const char *path, int flags, ...);
|
|
|
|
CWD_API int virtual_creat(const char *path, mode_t mode);
|
|
|
|
CWD_API int virtual_rename(const char *oldname, const char *newname);
|
|
|
|
CWD_API int virtual_stat(const char *path, zend_stat_t *buf);
|
|
|
|
CWD_API int virtual_lstat(const char *path, zend_stat_t *buf);
|
|
|
|
CWD_API int virtual_unlink(const char *path);
|
|
|
|
CWD_API int virtual_mkdir(const char *pathname, mode_t mode);
|
|
|
|
CWD_API int virtual_rmdir(const char *pathname);
|
|
|
|
CWD_API DIR *virtual_opendir(const char *pathname);
|
|
|
|
CWD_API FILE *virtual_popen(const char *command, const char *type);
|
|
|
|
CWD_API int virtual_access(const char *pathname, int mode);
|
2002-10-04 09:04:00 +08:00
|
|
|
|
2024-06-12 04:47:05 +08:00
|
|
|
#ifdef HAVE_UTIME
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API int virtual_utime(const char *filename, struct utimbuf *buf);
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API int virtual_chmod(const char *filename, mode_t mode);
|
2016-11-12 18:20:01 +08:00
|
|
|
#if !defined(ZEND_WIN32)
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int link);
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif
|
|
|
|
|
2010-09-13 17:08:42 +08:00
|
|
|
/* One of the following constants must be used as the last argument
|
2006-11-14 17:15:55 +08:00
|
|
|
in virtual_file_ex() call. */
|
|
|
|
|
2020-08-28 21:41:27 +08:00
|
|
|
// TODO Make this into an enum
|
2018-07-25 11:38:50 +08:00
|
|
|
#define CWD_EXPAND 0 /* expand "." and ".." but don't resolve symlinks */
|
2006-11-14 17:15:55 +08:00
|
|
|
#define CWD_FILEPATH 1 /* resolve symlinks if file is exist otherwise expand */
|
|
|
|
#define CWD_REALPATH 2 /* call realpath(), resolve symlinks. File must exist */
|
2006-11-13 23:13:20 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath);
|
2000-09-04 02:18:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API char *tsrm_realpath(const char *path, char *real_path);
|
2006-11-10 20:59:27 +08:00
|
|
|
|
2004-10-05 08:42:25 +08:00
|
|
|
#define REALPATH_CACHE_TTL (2*60) /* 2 minutes */
|
|
|
|
#define REALPATH_CACHE_SIZE 0 /* disabled while php.ini isn't loaded */
|
|
|
|
|
|
|
|
typedef struct _realpath_cache_bucket {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_ulong key;
|
2004-10-05 08:42:25 +08:00
|
|
|
char *path;
|
|
|
|
char *realpath;
|
2014-09-13 03:31:25 +08:00
|
|
|
struct _realpath_cache_bucket *next;
|
|
|
|
time_t expires;
|
2016-11-13 23:48:36 +08:00
|
|
|
uint16_t path_len;
|
|
|
|
uint16_t realpath_len;
|
|
|
|
uint8_t is_dir:1;
|
2015-07-05 00:55:22 +08:00
|
|
|
#ifdef ZEND_WIN32
|
2016-11-13 23:48:36 +08:00
|
|
|
uint8_t is_rvalid:1;
|
|
|
|
uint8_t is_readable:1;
|
|
|
|
uint8_t is_wvalid:1;
|
|
|
|
uint8_t is_writable:1;
|
2009-06-16 08:07:05 +08:00
|
|
|
#endif
|
2004-10-05 08:42:25 +08:00
|
|
|
} realpath_cache_bucket;
|
|
|
|
|
2000-09-04 02:18:13 +08:00
|
|
|
typedef struct _virtual_cwd_globals {
|
|
|
|
cwd_state cwd;
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_long realpath_cache_size;
|
|
|
|
zend_long realpath_cache_size_limit;
|
|
|
|
zend_long realpath_cache_ttl;
|
2004-10-05 08:42:25 +08:00
|
|
|
realpath_cache_bucket *realpath_cache[1024];
|
2000-09-04 02:18:13 +08:00
|
|
|
} virtual_cwd_globals;
|
|
|
|
|
|
|
|
#ifdef ZTS
|
reworked the patch, less new stuff but worky
TLS is already used in TSRM, the way exporting the tsrm cache through
a thread local variable is not portable. Additionally, the current
patch suffers from bugs which are hard to find, but prevent it to
be worky with apache. What is done here is mainly uses the idea
from the RFC patch, but
- __thread variable is removed
- offset math and declarations are removed
- extra macros and definitions are removed
What is done merely is
- use an inline function to access the tsrm cache. The function uses
the portable tsrm_tls_get macro which is cheap
- all the TSRM_* macros are set to placebo. Thus this opens the way
remove them later
Except that, the logic is old. TSRMLS_FETCH will have to be done once
per thread, then tsrm_get_ls_cache() can be used. Things seeming to be
worky are cli, cli server and apache. I also tried to enable bz2
shared and it has worked out of the box. The change is yet minimal
diffing to the current master bus is a worky start, IMHO. Though will
have to recheck the other previously done SAPIs - embed and cgi.
The offsets can be added to the tsrm_resource_type struct, then
it'll not be needed to declare them in the userspace. Even the
"done" member type can be changed to int16 or smaller, then adding
the offset as int16 will not change the struct size. As well on the
todo might be removing the hashed storage, thread_id != thread_id and
linked list logic in favour of the explicit TLS operations.
2014-09-26 00:48:27 +08:00
|
|
|
extern ts_rsrc_id cwd_globals_id;
|
2019-03-14 08:01:01 +08:00
|
|
|
extern size_t cwd_globals_offset;
|
|
|
|
# define CWDG(v) ZEND_TSRMG_FAST(cwd_globals_offset, virtual_cwd_globals *, v)
|
2000-09-04 02:18:13 +08:00
|
|
|
#else
|
2004-10-05 08:42:25 +08:00
|
|
|
extern virtual_cwd_globals cwd_globals;
|
2000-09-04 02:18:13 +08:00
|
|
|
# define CWDG(v) (cwd_globals.v)
|
|
|
|
#endif
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API void realpath_cache_clean(void);
|
2016-12-22 21:56:47 +08:00
|
|
|
CWD_API void realpath_cache_del(const char *path, size_t path_len);
|
|
|
|
CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, size_t path_len, time_t t);
|
2014-12-14 06:06:14 +08:00
|
|
|
CWD_API zend_long realpath_cache_size(void);
|
|
|
|
CWD_API zend_long realpath_cache_max_buckets(void);
|
|
|
|
CWD_API realpath_cache_bucket** realpath_cache_get_buckets(void);
|
2007-01-22 17:31:46 +08:00
|
|
|
|
2017-08-14 06:44:19 +08:00
|
|
|
#ifdef CWD_EXPORTS
|
|
|
|
extern void virtual_cwd_main_cwd_init(uint8_t);
|
|
|
|
#endif
|
|
|
|
|
2000-09-04 12:18:38 +08:00
|
|
|
/* The actual macros to be used in programs using TSRM
|
|
|
|
* If the program defines VIRTUAL_DIR it will use the
|
2010-09-13 17:08:42 +08:00
|
|
|
* virtual_* functions
|
2000-09-04 12:18:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef VIRTUAL_DIR
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_GETCWD(buff, size) virtual_getcwd(buff, size)
|
|
|
|
#define VCWD_FOPEN(path, mode) virtual_fopen(path, mode)
|
2001-08-05 09:34:40 +08:00
|
|
|
/* Because open() has two modes, we have to macros to replace it */
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_OPEN(path, flags) virtual_open(path, flags)
|
|
|
|
#define VCWD_OPEN_MODE(path, flags, mode) virtual_open(path, flags, mode)
|
|
|
|
#define VCWD_CREAT(path, mode) virtual_creat(path, mode)
|
|
|
|
#define VCWD_CHDIR(path) virtual_chdir(path)
|
2023-04-19 22:59:20 +08:00
|
|
|
#define VCWD_CHDIR_FILE(path) virtual_chdir_file(path, (int (*)(const char *)) virtual_chdir)
|
2001-04-30 20:45:02 +08:00
|
|
|
#define VCWD_GETWD(buf)
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_REALPATH(path, real_path) virtual_realpath(path, real_path)
|
|
|
|
#define VCWD_RENAME(oldname, newname) virtual_rename(oldname, newname)
|
|
|
|
#define VCWD_STAT(path, buff) virtual_stat(path, buff)
|
|
|
|
# define VCWD_LSTAT(path, buff) virtual_lstat(path, buff)
|
|
|
|
#define VCWD_UNLINK(path) virtual_unlink(path)
|
|
|
|
#define VCWD_MKDIR(pathname, mode) virtual_mkdir(pathname, mode)
|
|
|
|
#define VCWD_RMDIR(pathname) virtual_rmdir(pathname)
|
|
|
|
#define VCWD_OPENDIR(pathname) virtual_opendir(pathname)
|
|
|
|
#define VCWD_POPEN(command, type) virtual_popen(command, type)
|
|
|
|
#define VCWD_ACCESS(pathname, mode) virtual_access(pathname, mode)
|
2024-06-12 04:47:05 +08:00
|
|
|
#ifdef HAVE_UTIME
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_UTIME(path, time) virtual_utime(path, time)
|
2000-09-04 12:18:38 +08:00
|
|
|
#endif
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_CHMOD(path, mode) virtual_chmod(path, mode)
|
2016-11-12 18:20:01 +08:00
|
|
|
#if !defined(ZEND_WIN32)
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group, 0)
|
2024-06-12 04:47:05 +08:00
|
|
|
#ifdef HAVE_LCHOWN
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_LCHOWN(path, owner, group) virtual_chown(path, owner, group, 1)
|
2000-09-04 12:18:38 +08:00
|
|
|
#endif
|
2006-04-10 19:56:18 +08:00
|
|
|
#endif
|
2000-09-04 12:18:38 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-04-30 20:45:02 +08:00
|
|
|
#define VCWD_CREAT(path, mode) creat(path, mode)
|
2008-04-24 15:45:01 +08:00
|
|
|
/* rename on windows will fail if newname already exists.
|
|
|
|
MoveFileEx has to be used */
|
2015-07-05 00:55:22 +08:00
|
|
|
#if defined(ZEND_WIN32)
|
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
|
|
|
#define VCWD_FOPEN(path, mode) php_win32_ioutil_fopen(path, mode)
|
|
|
|
#define VCWD_OPEN(path, flags) php_win32_ioutil_open(path, flags)
|
|
|
|
#define VCWD_OPEN_MODE(path, flags, mode) php_win32_ioutil_open(path, flags, mode)
|
|
|
|
# define VCWD_RENAME(oldname, newname) php_win32_ioutil_rename(oldname, newname)
|
|
|
|
#define VCWD_MKDIR(pathname, mode) php_win32_ioutil_mkdir(pathname, mode)
|
|
|
|
#define VCWD_RMDIR(pathname) php_win32_ioutil_rmdir(pathname)
|
|
|
|
#define VCWD_UNLINK(path) php_win32_ioutil_unlink(path)
|
|
|
|
#define VCWD_CHDIR(path) php_win32_ioutil_chdir(path)
|
|
|
|
#define VCWD_ACCESS(pathname, mode) tsrm_win32_access(pathname, mode)
|
|
|
|
#define VCWD_GETCWD(buff, size) php_win32_ioutil_getcwd(buff, size)
|
|
|
|
#define VCWD_CHMOD(path, mode) php_win32_ioutil_chmod(path, mode)
|
2008-04-24 15:45:01 +08:00
|
|
|
#else
|
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
|
|
|
#define VCWD_FOPEN(path, mode) fopen(path, mode)
|
|
|
|
#define VCWD_OPEN(path, flags) open(path, flags)
|
|
|
|
#define VCWD_OPEN_MODE(path, flags, mode) open(path, flags, mode)
|
2008-04-24 15:45:01 +08:00
|
|
|
# define VCWD_RENAME(oldname, newname) rename(oldname, newname)
|
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
|
|
|
#define VCWD_MKDIR(pathname, mode) mkdir(pathname, mode)
|
|
|
|
#define VCWD_RMDIR(pathname) rmdir(pathname)
|
|
|
|
#define VCWD_UNLINK(path) unlink(path)
|
2001-04-30 20:45:02 +08:00
|
|
|
#define VCWD_CHDIR(path) chdir(path)
|
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
|
|
|
#define VCWD_ACCESS(pathname, mode) access(pathname, mode)
|
|
|
|
#define VCWD_GETCWD(buff, size) getcwd(buff, size)
|
|
|
|
#define VCWD_CHMOD(path, mode) chmod(path, mode)
|
|
|
|
#endif
|
|
|
|
|
2001-04-30 20:45:02 +08:00
|
|
|
#define VCWD_CHDIR_FILE(path) virtual_chdir_file(path, chdir)
|
|
|
|
#define VCWD_GETWD(buf) getwd(buf)
|
2006-11-10 23:04:07 +08:00
|
|
|
#define VCWD_STAT(path, buff) php_sys_stat(path, buff)
|
2001-04-30 20:45:02 +08:00
|
|
|
#define VCWD_LSTAT(path, buff) lstat(path, buff)
|
|
|
|
#define VCWD_OPENDIR(pathname) opendir(pathname)
|
|
|
|
#define VCWD_POPEN(command, type) popen(command, type)
|
2001-08-05 09:34:40 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
#define VCWD_REALPATH(path, real_path) tsrm_realpath(path, real_path)
|
2001-08-05 09:34:40 +08:00
|
|
|
|
2024-06-12 04:47:05 +08:00
|
|
|
#ifdef HAVE_UTIME
|
2015-07-05 00:55:22 +08:00
|
|
|
# ifdef ZEND_WIN32
|
2009-08-25 17:16:53 +08:00
|
|
|
# define VCWD_UTIME(path, time) win32_utime(path, time)
|
|
|
|
# else
|
|
|
|
# define VCWD_UTIME(path, time) utime(path, time)
|
|
|
|
# endif
|
2000-09-04 12:18:38 +08:00
|
|
|
#endif
|
2009-08-25 17:16:53 +08:00
|
|
|
|
2016-11-12 18:20:01 +08:00
|
|
|
#if !defined(ZEND_WIN32)
|
2001-08-05 09:34:40 +08:00
|
|
|
#define VCWD_CHOWN(path, owner, group) chown(path, owner, group)
|
2024-06-12 04:47:05 +08:00
|
|
|
#ifdef HAVE_LCHOWN
|
2006-03-06 02:57:54 +08:00
|
|
|
#define VCWD_LCHOWN(path, owner, group) lchown(path, owner, group)
|
2000-09-04 12:18:38 +08:00
|
|
|
#endif
|
2006-04-10 19:56:18 +08:00
|
|
|
#endif
|
2000-09-04 12:18:38 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-05-25 19:47:31 +08:00
|
|
|
/* Global stat declarations */
|
|
|
|
#ifndef _S_IFDIR
|
|
|
|
#define _S_IFDIR S_IFDIR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _S_IFREG
|
|
|
|
#define _S_IFREG S_IFREG
|
|
|
|
#endif
|
|
|
|
|
2015-05-26 00:07:47 +08:00
|
|
|
#ifndef S_IFLNK
|
2016-12-22 09:17:55 +08:00
|
|
|
#define _IFLNK 0120000 /* symbolic link */
|
|
|
|
#define S_IFLNK _IFLNK
|
2015-05-26 00:07:47 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-25 19:17:35 +08:00
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
|
|
|
|
#endif
|
|
|
|
|
2015-05-25 19:47:31 +08:00
|
|
|
#ifndef S_IXROOT
|
2015-05-25 19:17:35 +08:00
|
|
|
#define S_IXROOT ( S_IXUSR | S_IXGRP | S_IXOTH )
|
2015-05-25 19:47:31 +08:00
|
|
|
#endif
|
2015-05-25 19:17:35 +08:00
|
|
|
|
2016-12-22 09:17:55 +08:00
|
|
|
/* XXX should be _S_IFIFO? */
|
|
|
|
#ifndef S_IFIFO
|
|
|
|
#define _IFIFO 0010000 /* fifo */
|
|
|
|
#define S_IFIFO _IFIFO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_IFBLK
|
|
|
|
#define _IFBLK 0060000 /* block special */
|
|
|
|
#define S_IFBLK _IFBLK
|
|
|
|
#endif
|
|
|
|
|
2000-09-04 02:18:13 +08:00
|
|
|
#endif /* VIRTUAL_CWD_H */
|