Commit Graph

762 Commits

Author SHA1 Message Date
Xinchen Hui
ce6ad9bdd9 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: (48 commits)
  Update NEWs
  Unused label
  Fixed bug #72853 (stream_set_blocking doesn't work)
  fix test
  Bug #72663 - part 3
  Bug #72663 - part 2
  Bug #72663 - part 1
  Update NEWS
  BLock test with memory leak
  fix tests
  Fix TSRM build
  Fix bug #72850 - integer overflow in uuencode
  Fixed bug #72849 - integer overflow in urlencode
  Fix bug #72848 - integer overflow in quoted_printable_encode caused heap corruption
  Fix bug #72838 - 	Integer overflow lead to heap corruption in sql_regcase
  Fix bug #72837 - integer overflow in bzdecompress caused heap corruption
  Fix bug #72836 - integer overflow in base64_decode caused heap corruption
  Fix for bug #72807 - do not produce strings with negative length
  Fix for bug #72790 and bug #72799
  Fix bug #72730 - imagegammacorrect allows arbitrary write access
  ...

Conflicts:
	ext/standard/var_unserializer.c
2016-08-17 17:14:30 +08:00
Xinchen Hui
3956deb1b2 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Fixed bug #72853 (stream_set_blocking doesn't work)

Conflicts:
	main/streams/plain_wrapper.c
2016-08-17 16:56:02 +08:00
Xinchen Hui
abe00908af Fixed bug #72853 (stream_set_blocking doesn't work)
Implemented  PHP_STREAM_OPTION_META_DATA_API for plain_wrappers
2016-08-17 16:54:21 +08:00
Xinchen Hui
3800e1cf97 Fixed bug #72743 (Out-of-bound read in php_stream_filter_create) 2016-08-04 19:10:40 +08:00
Pierrick Charron
929c1e0cdf Merge branch 'PHP-7.0' into PHP-7.1 2016-07-27 00:39:47 -04:00
Pierrick Charron
6714f73545 Merge branch 'PHP-5.6' into PHP-7.0
Conflicts:
	main/streams/streams.c
2016-07-27 00:38:54 -04:00
Pierrick Charron
074b86d845 Fixed bug #72686 (zlib: url support is broken).
zlib: support is broken since a really long time.
It never worked on versions >= PHP5.6 so we can just remove
this dead code.

Bug was introduced 2006-05-14 (Before 5.2.0)
2016-07-27 00:33:13 -04:00
Lauri Kenttä
7a02704c0e Require strict base64 in data URI
As the tests already show, the data URI wrapper is supposed to fail
for corrupt input, but for some reason, one case of invalid input is
still allowed to pass?! Strict base64 makes a lot more sense here.
Also, Chromium and Firefox fail on invalid base64, so it's a logical
choice for PHP as well.
2016-07-22 18:03:55 +02:00
Xinchen Hui
4fb5885bf8 Merge branch 'PHP-7.0'
* PHP-7.0:
  Fixed bug #72505 (readfile() mangles files larger than 2G)
2016-06-28 11:12:01 +08:00
Xinchen Hui
c73a2f7f45 Fixed bug #72505 (readfile() mangles files larger than 2G) 2016-06-28 11:11:25 +08:00
Dmitry Stogov
1433162083 Fixed compilation warnings 2016-06-21 20:12:29 +03:00
Dmitry Stogov
1616038698 Added ZEND_ATTRIBUTE_FORMAT to some middind functions.
"%p" replaced by ZEND_LONG_FMT to avoid compilation warnings.
Fixed most incorrect use cases of format specifiers.
2016-06-21 16:00:37 +03:00
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
3e1329c184 Merge branch 'PHP-7.0' 2016-06-18 21:34:33 -07:00
Xinchen Hui
6b83832cf4 Merge branch 'PHP-5.6' into PHP-7.0
Conflicts:
	main/streams/xp_socket.c
2016-06-18 21:33:54 -07:00
Xinchen Hui
c4c1993af6 Fixed bug #72439 (Stream socket with remote address leads to a segmentation fault) 2016-06-18 21:29:47 -07:00
Joe Watkins
66fc5a3436 Implement #51879 stream context socket option tcp_nodelay 2016-04-29 12:11:58 +01:00
Joe Watkins
c2ef11e86f Merge branch 'PHP-7.0'
* PHP-7.0:
  simplify expression
2016-04-28 15:50:36 +01:00
Joe Watkins
f580540c8d simplify expression 2016-04-28 15:50:27 +01:00
Dmitry Stogov
6499162ff0 - get rid of EG(scope). zend_get_executed_scope() should be used instead.
- ichanged zval_update_constant_ex(). Use IS_TYPE_IMMUTABLE flag on shared constants and AST, instead of "inline_change" parameter.
2016-04-28 04:13:34 +03:00
Dmitry Stogov
f0a2e8eb13 Removed "zend_fcall_info.function_table". It was assigned in many places, but is never used. 2016-04-27 13:46:38 +03:00
Dmitry Stogov
c67c166f93 Removed zend_fcall_info.symbol_table 2016-03-02 17:50:55 +03:00
Stanislav Malyshev
d25e67eee6 Fix bug #71629: sync php_url_decode definition 2016-02-21 17:11:34 -08:00
Stanislav Malyshev
e231830f16 Merge branch 'PHP-5.6.18' into PHP-7.0.3
* PHP-5.6.18:
  fix tests
  fix NEWS
  Update NEWS
  update NEWS
  Fixed bug #71488: Stack overflow when decompressing tar archives
  update NEWS
  add missing headers for SIZE_MAX
  backport the escapeshell* functions hardening branch
  add tests
  Fix bug #71459 - Integer overflow in iptcembed()
  prepare 5.6.18RC1
  Fix test when run with openssl < 1.0.2 (reorder so no more SSLv2 message) Fix skip message to work
  improve fix for bug #71201
  Fixed bug #71323 - Output of stream_get_meta_data can be falsified by its input
  Fix bug #71391: NULL Pointer Dereference in phar_tar_setupmetadata()
  Fixed bug #71331 - Uninitialized pointer in phar_make_dirstream()
  Fix bug #71335: Type Confusion in WDDX Packet Deserialization
  Fix bug #71354 - remove UMR when size is 0

Conflicts:
	configure.in
	ext/phar/dirstream.c
	ext/phar/phar_object.c
	ext/phar/tar.c
	ext/standard/exec.c
	ext/standard/iptc.c
	ext/standard/math.c
	ext/standard/streamsfuncs.c
	ext/wddx/wddx.c
	main/php_version.h
	main/streams/memory.c
2016-02-01 20:00:01 -08:00
Stanislav Malyshev
309ead112f Merge branch 'PHP-5.5.32' into PHP-5.6.18
* PHP-5.5.32:
  Fixed bug #71488: Stack overflow when decompressing tar archives
  update NEWS
  add missing headers for SIZE_MAX
  backport the escapeshell* functions hardening branch
  add tests
  Fix bug #71459 - Integer overflow in iptcembed()
  Fixed bug #71323 - Output of stream_get_meta_data can be falsified by its input
  Fix bug #71391: NULL Pointer Dereference in phar_tar_setupmetadata()
  Fix bug #71335: Type Confusion in WDDX Packet Deserialization
  Fix bug #71354 - remove UMR when size is 0
2016-02-01 18:32:31 -08:00
Stanislav Malyshev
6297a117d7 Fixed bug #71323 - Output of stream_get_meta_data can be falsified by its input 2016-01-16 22:10:54 -08: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
da028e0757 This should be better 2015-12-30 05:10:05 -08:00
Caleb Champlin
6ff014b31c Make sure context is set to null to prevent use after free 2015-11-09 11:58:34 +08:00
Bob Weinand
855bb36fd0 Add support for IPV6_V6ONLY on sockets 2015-11-06 21:45:31 +01:00
Dmitry Stogov
c67fc6bb09 Fixed memory leak in php_stream_context_set_option() 2015-10-29 20:06:55 +03:00
Dmitry Stogov
560e4fa393 Removed or simplified incorrect SEPARATE_*() macros usage. 2015-09-29 11:17:43 +03:00
Anatol Belski
9d82a7dc98 add overflow check 2015-09-02 17:05:45 +02:00
Anatol Belski
797e30f4fc Fixed bug #70198 Checking liveness does not work as expected 2015-08-11 17:36:10 +02:00
Anatol Belski
20e765b841 Fixed bug #69900 Too long timeout on pipes 2015-07-28 10:28:45 +02:00
Xinchen Hui
9834cd9339 Revert "Revert "suggest parentheses around ‘&&’ within ‘||’""
This reverts commit ec1e8929c4.
2015-08-11 22:34:39 +08:00
Xinchen Hui
ec1e8929c4 Revert "suggest parentheses around ‘&&’ within ‘||’"
This reverts commit 4f2c0e0451.
2015-08-11 22:14:37 +08:00
Xinchen Hui
4f2c0e0451 suggest parentheses around ‘&&’ within ‘||’ 2015-08-11 21:43:38 +08:00
Anatol Belski
7eb6bd1311 add EAGAIN checks
EAGAIN and EWOULDBLOCK should be checked together and don't necessary,
have same value. So checking both is better for portability.
2015-08-11 15:17:25 +02:00
Anatol Belski
24f0fe6b1f Fixed bug #70198 Checking liveness does not work as expected 2015-08-11 14:40:34 +02:00
Anatol Belski
6f3dd4d45b fix pipe peek timeout 2015-07-02 15:19:38 +02:00
Christoph M. Becker
58b982afed Fix alignment on 32-bit 2015-07-02 14:23:07 +02:00
Anatol Belski
4e5758f377 fix c/p issue 2015-07-02 14:22:58 +02:00
Anatol Belski
734d907aa4 initial stuff to make allow blocking pipes on windows 2015-07-02 14:22:55 +02:00
Dmitry Stogov
7aa7627172 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 13:59:27 +03:00
Bob Weinand
6ad9cd5367 Only call stream_flush if anything was written
This avoids flushing in readonly mode upon close
2015-06-30 03:49:54 +02:00
Dmitry Stogov
4bd22cf1c1 Improved zend_string API (Francois Laupretre)
Squashed commit of the following:

commit d96eab8d79
Author: Francois Laupretre <francois@tekwire.net>
Date:   Fri Jun 26 01:23:31 2015 +0200

    Use the new 'ZSTR' macros in the rest of the code.

    Does not change anything to the generated code (thanks to compat macros) but cleaner.

commit b352643910
Author: Francois Laupretre <francois@tekwire.net>
Date:   Thu Jun 25 13:45:06 2015 +0200

    Improve zend_string API

    Add missing methods
2015-06-29 16:44:54 +03:00
Anatol Belski
c444c4172f further cleanups with S_IF* macros generalized declarations 2015-05-25 18:03:28 +02:00
Di Wu
c7492ed224 Fix undeclared identifier 'PHP_STREAM_KEEP_RSRC'
Identifier named `PHP_STREAM_FREE_KEEP_RSRC`  but use `PHP_STREAM_KEEP_RSRC`

Reference Line 131
2015-04-09 18:16:53 +02:00