Commit Graph

977 Commits

Author SHA1 Message Date
Dmitry Stogov
9c2a1f52a5 Avoid useless dereferences and separations during paramter passing. 2017-06-19 12:55:59 +03:00
Dmitry Stogov
3a4fcee767 trim() micro-optimization 2017-05-30 17:14:08 +03:00
Dmitry Stogov
dd4a78b631 Don't separate output arguments 2017-05-23 17:18:05 +03:00
Dmitry Stogov
a08723d3d3 Use interned empty and "one char" strings. 2017-05-18 17:59:59 +03:00
Anatol Belski
c698299550 Interned strings unification for TS/NTS
Hereby, interned strings are supported in thread safe PHP. The patch
implements two types of interned strings

- interning per process, strings are not freed till process end
- interning per request, strings are freed at request end

There is no runtime interning.

With Opcache, all the permanent iterned strings are copied into SHM on
startup, additional copying into SHM might happen on demand.
2017-03-04 10:39:13 +01:00
Nikita Popov
2634b13e88 Deprecate parse_str() without second argument 2017-02-03 18:52:57 +01:00
Nikita Popov
5537a4e2b8 Merge branch 'PHP-7.1' 2017-02-03 17:55:08 +01:00
Nikita Popov
8660e95b4c Fixed bug #74041 2017-02-03 17:54:39 +01:00
Stanislav Malyshev
cbc416e8d3 Merge branch 'PHP-7.1'
* PHP-7.1:
  Fix bug #73648 - integer overflow in substr
2017-01-16 12:14:10 -08:00
Stanislav Malyshev
05f2f730e6 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fix bug #73648 - integer overflow in substr
2017-01-16 12:14:03 -08:00
Stanislav Malyshev
d1d002fc4d Fix bug #73648 - integer overflow in substr 2017-01-16 12:11:50 -08:00
Joe Watkins
7fd318bc4c
Merge branch 'PHP-7.1'
* PHP-7.1:
  Fixed bug #72979 money_format stores wrong length on AIX
2017-01-09 05:33:48 +00:00
Joe Watkins
bf6eb65673
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Fixed bug #72979 money_format stores wrong length on AIX
2017-01-09 05:32:50 +00:00
Joe Watkins
8dd523a216
Fixed bug #72979 money_format stores wrong length on AIX 2017-01-09 05:31:41 +00:00
Sammy Kaye Powers
dac6c639bb Update copyright headers to 2017 2017-01-04 11:23:42 -06:00
Sammy Kaye Powers
478f119ab9 Update copyright headers to 2017 2017-01-04 11:14:55 -06:00
Sammy Kaye Powers
9e29f841ce Update copyright headers to 2017 2017-01-02 09:30:12 -06:00
Sara Golemon
a23f08a33c Use new param API in standard 2016-12-30 17:28:55 -08:00
Sara Golemon
331dcf08df Use new param API in standard/string 2016-12-30 16:40:45 -08:00
Stanislav Malyshev
c4ebe4da04 Merge branch 'PHP-7.1'
* PHP-7.1:
  Add more mbfl string size checks (bug #73505)
2016-11-26 14:48:57 -08:00
Stanislav Malyshev
dd7eee0609 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  Add more mbfl string size checks (bug #73505)
2016-11-26 14:48:50 -08:00
Stanislav Malyshev
58cdd03d92 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Add more mbfl string size checks (bug #73505)
2016-11-26 14:48:40 -08:00
Stanislav Malyshev
5ee02b207d Add more mbfl string size checks (bug #73505) 2016-11-26 14:47:58 -08:00
Levi Morrison
5ff2990cb3 Refactor: rename variables to match documentation
Rename 'arr' to 'pieces'
Rename 'delim' to 'glue'
2016-11-20 14:54:06 -07:00
Kalle Sommer Nielsen
2104bea5d7 Remove Netware support
If this does not break the Unix system somehow, I'll be amazed. This should get most of it out, apologies for any errors this may cause on non-Windows ends which I cannot test atm.
2016-11-12 11:20:01 +01:00
Andrea Faulds
1a512eed44 Move utf8_encode and utf8_decode to ext/standard 2016-10-17 15:39:02 +01:00
Anatol Belski
0ca15cbeba reduce size of stream struct
32 bytes are spared on 64-bit build
2016-10-05 22:53:21 +02:00
Stanislav Malyshev
8ea01d5f19 Apparently negative wordwrap is a thing and should work as length = 0.
I'll leave it as is for now.
2016-10-03 19:17:42 -07:00
Stanislav Malyshev
631173aa5c Really fix bug #73017 2016-10-03 18:07:21 -07:00
Anatol Belski
2088e3eb45 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  pick up the safe alloc pieces from 19866fb76c
2016-09-13 11:51:17 +02:00
Anatol Belski
c403b30291 pick up the safe alloc pieces from
19866fb76c
2016-09-13 11:50:18 +02:00
Stanislav Malyshev
65c8caafa8 Also fix overflow in wordwrap 2016-09-12 21:04:23 -07:00
Stanislav Malyshev
19866fb76c Fix various int size overflows.
Add function for detection of string zvals with length that does not fit
INT_MAX.
2016-09-12 21:04:23 -07:00
Andrea Faulds
fc5497cb92 Merge branch 'PHP-7.0' into PHP-7.1 2016-09-11 22:46:20 +01:00
Andrea Faulds
d690014bf3 Remove zpp fallback code (always use Fast ZPP)
Squashed commit of the following:

commit 3e27fbb3d2
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sun Sep 11 19:14:37 2016 +0100

    Keep dummy FAST_ZPP macro for compatibility

commit 8a7cfd00de
Author: Andrea Faulds <ajf@ajf.me>
Date:   Mon Sep 5 22:36:03 2016 +0100

    Remove FAST_ZPP macro and plain zpp fallback code
2016-09-11 22:44:46 +01:00
Anatol Belski
50c5d13d26 Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
  fix leak
2016-08-29 15:44:13 +02:00
Anatol Belski
d80a317c0b fix leak 2016-08-29 15:43:10 +02:00
Christoph M. Becker
ae3b2078ea Fix #72823: strtr out-of-bound access
If php_strtr_array_prepare_repls() reports pattern_len == 0, we return
early to avoid OOB accesses, and because there is nothing to replace anyway.
2016-08-13 11:40:33 +02:00
Nikita Popov
e52c1f3ca9 Merge branch 'PHP-7.0' into PHP-7.1 2016-08-07 18:50:27 +02:00
Lauri Kenttä
e616bc8694 Fix bug #55451
Make substr_compare ignore the length if it's NULL. This allows to
use the last parameter (case_insensitivity) with the default length.
2016-08-07 18:48:36 +02:00
Julien Pauli
4b483cdc9a Merge branch 'PHP-7.0'
* PHP-7.0:
  Updated NEWS
  Updated NEWS
  Backported bug #71144 (Segmentation fault when using cURL with ZTS)
  fix bug #72024 (microtime() leaks memory)
2016-07-08 15:06:36 +02:00
Julien Pauli
87fe485c35 Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
  Updated NEWS
  Backported bug #71144 (Segmentation fault when using cURL with ZTS)
  fix bug #72024 (microtime() leaks memory)

Conflicts:
	ext/curl/interface.c
2016-07-08 15:05:13 +02:00
Michael Maroszek
0be13d2dc2 fix bug #72024 (microtime() leaks memory) 2016-07-08 14:36:44 +02:00
Stanislav Malyshev
b8487b6a7d Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
  Fix the fix for #72403 on nl2br
  5.5.38 now

Conflicts:
	configure.in
	main/php_version.h
2016-06-27 12:32:11 -07:00
Stanislav Malyshev
25bd11cf27 Fix the fix for #72403 on nl2br 2016-06-27 12:30:42 -07:00
Dmitry Stogov
adc95c5114 Fixed compilation warnings 2016-06-23 12:47:06 +03:00
Stanislav Malyshev
c9b24ef307 Merge branch 'PHP-5.6.23' into PHP-5.6
* PHP-5.6.23:
  Fixed bug #72446 - Integer Overflow in gdImagePaletteToTrueColor() resulting in heap overflow
  update NEWS
  fix tests
  fix build
  Fix bug #72455:  Heap Overflow due to integer overflows
  Fix bug #72434: ZipArchive class Use After Free Vulnerability in PHP's GC algorithm and unserialize
  Fixed ##72433: Use After Free Vulnerability in PHP's GC algorithm and unserialize
  Fix bug #72407: NULL Pointer Dereference at _gdScaleVert
  Fix bug #72402: _php_mb_regex_ereg_replace_exec - double free
  Fix bug #72298	pass2_no_dither out-of-bounds access
  Fixed #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
  Fix bug #72262 - do not overflow int
  Fix bug #72400 and #72403 - prevent signed int overflows for string lengths
  Fix bug #72275: don't allow smart_str to overflow int
  Fix bug #72340: Double Free Courruption in wddx_deserialize
  Fix bug #72321 - use efree() for emalloc allocation
  5.6.23RC1

Conflicts:
	configure.in
	main/php_version.h
2016-06-21 00:02:37 -07:00
Stanislav Malyshev
7dde353ee7 Merge branch 'PHP-5.5' into PHP-5.6.23
* PHP-5.5:
  Fixed bug #72446 - Integer Overflow in gdImagePaletteToTrueColor() resulting in heap overflow
  update NEWS
  fix tests
  fix build
  Fix bug #72455:  Heap Overflow due to integer overflows
  Fix bug #72434: ZipArchive class Use After Free Vulnerability in PHP's GC algorithm and unserialize
  Fixed ##72433: Use After Free Vulnerability in PHP's GC algorithm and unserialize
  Fix bug #72407: NULL Pointer Dereference at _gdScaleVert
  Fix bug #72402: _php_mb_regex_ereg_replace_exec - double free
  Fix bug #72298	pass2_no_dither out-of-bounds access
  Fixed #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
  Fix bug #72262 - do not overflow int
  Fix bug #72400 and #72403 - prevent signed int overflows for string lengths
  Fix bug #72275: don't allow smart_str to overflow int
  Fix bug #72340: Double Free Courruption in wddx_deserialize
  update NEWS
  Fix #66387: Stack overflow with imagefilltoborder
  Skip test which is 64bits only
  5.5.37 now

Conflicts:
	configure.in
	ext/mcrypt/mcrypt.c
	ext/spl/spl_directory.c
	main/php_version.h
2016-06-21 00:01:48 -07: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
Stanislav Malyshev
88746d60ab Fix bug #72400 and #72403 - prevent signed int overflows for string lengths 2016-06-15 21:51:28 -07:00