Commit Graph

1120 Commits

Author SHA1 Message Date
Anatol Belski
3d3f11ede4 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 12:45:39 +02:00
Xinchen Hui
85fd260916 Merge branch 'PHP-7.0'
* PHP-7.0:
  Fixed(attempt to) bug #72405 (mb_ereg_replace - mbc_to_code (oniguruma) - oob read access)
2016-06-15 14:55:43 +08:00
Xinchen Hui
999a3553d5 Fixed(attempt to) bug #72405 (mb_ereg_replace - mbc_to_code (oniguruma) - oob read access)
according to ext/mbstring/oniguruma/enc/utf8.c, max bytes are 6
2016-06-15 14:54:57 +08:00
Xinchen Hui
14e790a075 Merge branch 'PHP-7.0' 2016-06-13 18:20:37 -07:00
Xinchen Hui
3d56418722 Fixed bug #72399 (Use-After-Free in MBString (search_re)) 2016-06-13 18:20:26 -07:00
Anatol Belski
628272ee6c Merge branch 'PHP-7.0'
* PHP-7.0:
  missing return
2016-06-06 07:34:34 +02:00
Anatol Belski
6ec8b2c57d Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  missing return
2016-06-06 07:33:36 +02:00
Anatol Belski
c05b417718 missing return 2016-06-06 07:28:12 +02:00
Nikita Popov
91f5940329 Forbid dynamic calls to scope introspection functions
Per RFC:
https://wiki.php.net/rfc/forbid_dynamic_scope_introspection
2016-05-24 20:48:24 +02:00
Xinchen Hui
23e362a46e Merge branch 'PHP-7.0'
* PHP-7.0:
  Fixed bug #72164 (Null Pointer Dereference - mb_ereg_replace)
2016-05-05 17:27:58 +08:00
Xinchen Hui
395863b1d1 Fixed bug #72164 (Null Pointer Dereference - mb_ereg_replace) 2016-05-05 17:27:34 +08:00
Kalle Sommer Nielsen
fcc6bdebc2 Added missing zend_parse_parameters_none() to mb_list_encodings() 2016-04-03 02:28:39 +02:00
Anatol Belski
d1ac9edc50 Merge branch 'PHP-7.0'
* PHP-7.0:
  Fixed bug #71704 php_snmp_error() Format String Vulnerability
  Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut
  Updated to version 2016.3 (2016c)
  Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut
  Fixed bug #71527 Buffer over-write in finfo_open with malformed magic file
  Fix bug #71798 - Integer Overflow in php_raw_url_encode
  update NEWS
  Disable huge pages in the Zend allocator by default As per the discussion on internals, this is an expert feature that needs special system-level configuration and care.
  Added ability to disable huge pages in Zend Memeory Manager through the environment variable USE_ZEND_ALLOC_HUGE_PAGES=0.
  Fix bug #71860: Require valid paths for phar filenames
  Fix bug #71860: Require valid paths for phar filenames
  update NEWS
  Fixed bug #71704 php_snmp_error() Format String Vulnerability
  Merge branch 'PHP-5.6' into PHP-7.0
  Updated to version 2016.2 (2016b)
  update libs versions
  set RC1 versions
  Going for 5.5.34
2016-03-29 11:27:39 +02:00
Stanislav Malyshev
67fbb06311 Merge branch 'PHP-5.5' into PHP-7.0.5
* PHP-5.5:
  Fixed bug #71704 php_snmp_error() Format String Vulnerability
  Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut
  Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut
  Fix bug #71798 - Integer Overflow in php_raw_url_encode
  Fix bug #71860: Require valid paths for phar filenames
  Going for 5.5.34

Conflicts:
	configure.in
	ext/phar/phar_object.c
	ext/phar/tests/badparameters.phpt
	ext/phar/tests/create_path_error.phpt
	ext/phar/tests/pharfileinfo_construct.phpt
	ext/snmp/snmp.c
	ext/standard/url.c
	main/php_version.h
2016-03-28 23:55:05 -07:00
Stanislav Malyshev
62da5cdf3d Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
  Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut
  Fix bug #71798 - Integer Overflow in php_raw_url_encode
  Fix bug #71860: Require valid paths for phar filenames
  Going for 5.5.34

Conflicts:
	configure.in
	ext/phar/tests/create_path_error.phpt
	main/php_version.h
2016-03-28 23:21:15 -07:00
Stanislav Malyshev
f8dd10508b Fixed bug #71906: AddressSanitizer: negative-size-param (-1) in mbfl_strcut 2016-03-28 23:15:16 -07:00
Francois Laupretre
d0d9e7251e mb_strpos()/mb_stripos(): Add support for negative offset 2016-03-09 14:41:38 +01:00
Francois Laupretre
882f97042b mb_ereg_search_setpos(): Add support for negative position
Also add missing test for this function
2016-03-09 14:41:38 +01:00
Francois Laupretre
70187267b4 mb_strimwidth(): Add support for negative 'start' and 'width' 2016-03-09 14:41:38 +01:00
Francois Laupretre
56fce8990f strpos()/stripos(): Add support for negative offsets 2016-03-09 14:41:37 +01:00
Anatol Belski
89a4342507 fix incompatible pointers on 64-bit 2016-03-07 22:01:44 +01:00
Nikita Popov
1ac152938c Move semicolon into TSRMLS_CACHE_EXTERN/DEFINE
Also re bug #71575.
2016-03-03 16:50:01 +01:00
Yasuo Ohgaki
f9c595f3c0 Fixed bug #65720 ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c:281: bad if test 2016-01-18 10:54:07 +09:00
Yasuo Ohgaki
7554478a4c Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Fixed bug #65720 ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c:281: bad if test
2016-01-18 10:52:11 +09:00
Yasuo Ohgaki
dc23f1f38f Fixed bug #65720 ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c:281: bad if test 2016-01-18 10:51:29 +09:00
Tim Düsterhus
e585696a0b Fixed bug 71397 (mb_send_mail segmentation fault) 2016-01-17 15:30:09 +01:00
Lior Kaplan
ed35de784f Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Happy new year (Update copyright to 2016)
2016-01-01 19:48:25 +02:00
Lior Kaplan
49493a2dcf Happy new year (Update copyright to 2016) 2016-01-01 19:21:47 +02:00
Xinchen Hui
84b997020e Fixed bug #71066 (mb_send_mail: Program terminated with signal SIGSEGV, Segmentation fault) 2015-12-08 17:47:16 -08:00
Lior Kaplan
e322fb0015 SIZEOF_SIZE_T doesn't exist on AIX, keep using SIZEOF_LONG
Follow up for 3689b444
2015-12-02 19:30:05 +02:00
Anatol Belski
2283551cfa fix NULL deref in mbstring post handler 2015-11-05 22:24:47 +01:00
Nikita Popov
1287c48082 Fix/improve zpp usage
The ext/interbase changes are done blindly, fingers crossed.

Some of these are bug fixes, some make zpp usage more idiomatic.
2015-10-02 09:35:00 +02:00
Xinchen Hui
e841016df7 Upgrade unicode_data.h to UnicodeData.txt 8.0.0 (part of bug #70475 ext/mbstring/unicode_data.h needs update) 2015-09-15 07:56:10 -07:00
Anatol Belski
46101dbec5 fix incompatible types
namely between hash_data_type and st_data_t
2015-08-15 12:03:47 +02:00
Anatol Belski
3689b44453 add SIZEOF_SIZE_T to oniguruma 2015-08-15 11:39:06 +02:00
Anatol Belski
228eaf5bc4 fix pointer truncation cases 2015-08-15 11:27:07 +02:00
Anatol Belski
4e66cce87c switch to the unified globals accessor where appropriate 2015-07-29 13:26:35 +02:00
Nikita Popov
f809f28119 Check mbfl_filt_put_invalid_char return value
And fix some libmbfl warnings
2015-07-18 21:53:03 +02:00
Nikita Popov
5c95226d50 Various warning fixes 2015-07-17 20:18:25 +02:00
Dmitry Stogov
4a2e40bb86 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 04:05:24 +03:00
olshevskiy87
8bdec7a248 fix typos
Signed-off-by: olshevskiy87 <olshevskiy87@bk.ru>
2015-05-13 22:28:35 +04:00
Lauri Kenttä
533c4be0d5 Fix compile error when oniguruma is not available 2015-04-13 10:11:38 +02:00
Nikita Popov
6ef9216269 Finish PHP 4 constructor deprecation 2015-03-31 17:55:27 +02:00
Andrea Faulds
db76b708cf Deprecate PHP 4 constructors 2015-03-31 17:55:27 +02:00
Anatol Belski
2d78023244 cleanup the mod version macros, round 2 2015-03-23 20:33:54 +01:00
Anatol Belski
0e30c543ec upgrade to oniguruman 5.9.6 2015-03-12 13:42:36 +01:00
Anatol Belski
ff337bf52b expose oniguruma version 2015-03-12 13:28:43 +01:00
Anatol Belski
4ee0395a4a init mbstring tsrm_ls_cache on MINIT
as some globals are accessed there already
2015-03-11 23:42:39 +01:00
Masaki Kagaya
9d81d7ff70 added missing parentheses
added test case for bug #68846
replaced tab with space
added missing parentheses again
See also: http://icu-project.org/docs/papers/gb18030.html#h7
2015-03-08 23:45:11 -07:00
Masaki Kagaya
934d6ed900 added missing parentheses
added test case for bug #68846
replaced tab with space
added missing parentheses again
See also: http://icu-project.org/docs/papers/gb18030.html#h7
2015-03-08 23:40:56 -07:00