1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 23:18:13 +02:00
Commit Graph

131938 Commits

Author SHA1 Message Date
Ilija Tovilo 5823955c78 Merge branch 'PHP-8.2'
* PHP-8.2:
  [skip ci] Fix Slack notification
2023-04-13 13:53:05 +02:00
Ilija Tovilo edd4980199 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Fix Slack notification
2023-04-13 13:52:42 +02:00
Ilija Tovilo 2eeff96df5 [skip ci] Fix Slack notification
ravsamhq/notify-slack-action doesn't work on MacOS, so we use curl directly.
2023-04-13 13:52:23 +02:00
Ilija Tovilo 49fd6306db Merge branch 'PHP-8.2'
* PHP-8.2:
  [skip ci] Skip bug45161.phpt on Windows
2023-04-13 13:21:18 +02:00
Ilija Tovilo 023e17a89d Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Skip bug45161.phpt on Windows
2023-04-13 13:20:45 +02:00
Mingli Yu adcb38b1ff xxhash.h: Fix GCC 12 -Og
Change whether to inline XXH3_hashLong_withSecret to a config option

Ref: https://github.com/Cyan4973/xxHash/commit/ace22bddc7a366a5dd8a71e8b8247694530684ec

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>

Closes GH-11062.
2023-04-13 12:20:20 +01:00
Ilija Tovilo 4b22c3e3ad [skip ci] Skip bug45161.phpt on Windows
See GH-10753

The test is insanely slow on Windows and it's unclear why. It might be a curl
issue.
2023-04-13 13:19:52 +02:00
Ilija Tovilo 92669d75f2 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix test bug60120.phpt
2023-04-13 12:58:02 +02:00
Ilija Tovilo de9ea68ad8 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix test bug60120.phpt
2023-04-13 12:57:10 +02:00
Ilija Tovilo dd44a9330e Fix test bug60120.phpt
The process cmd was broken. We're now also checking that the process output is
actually what we expect.

Closes GH-11064
2023-04-13 12:56:18 +02:00
Niels Dossche 00008a861a Remove unnecessary memory clearing in virtual_file_ex() (#10963)
I checked a simple Laravel CRUD application's home page under Callgrind
and found that the line:
  char resolved_path[MAXPATHLEN] = {0};
took up about 0.95% of the spent instruction count.
This is because when opcache revalidates the timestamps, it has to go
through the function virtual_file_ex() which contains that line. That
line will memset 4096 bytes on my system to all zeroes. This is bad for
the data cache and for the runtime.

I found that this memsetting is unnecessary in most cases, and that
we can fix the one remaining case:

* Lines 1020-1027 don't do anything with resolved_path, so that's okay.
* Lines 1033-1098:
  - The !IS_ABSOLUTE_PATH branch will always result in a memcpy from
    path to resolved_path (+ sometimes an offset) with the total copied
    amount equal to path_length+1, so that includes a NUL byte.
  - The else branch either takes the WIN32 path or the non-WIN32 path.
    ° WIN32: There's a copy from path+2 with length path_length-1.
             Note that we chop off the first 2 bytes, so this also
             includes the NUL byte.
    ° Non-WIN32: Copies path_length+1 bytes, so that includes a NUL byte.

At this point we know that resolved_path ends in a NUL byte. Going
further in the code:

* Lines 1100-1106 don't write to resolved_path, so no NUL byte is removed.
* Lines 1108-1136:
  - The IS_UNC_PATH branch:
    ° Lines 1111-1112 don't overwrite the NUL byte, because we know the
      path length is at least 2 due to the IS_UNC_PATH check.
    ° Both while loops uppercase the path until a slash is found. If a
      NUL byte was found then it jumps to verify. Therefore, no NUL byte
      can be overwritten. Furthermore, Lines 1121 and 1129 cannot
      overwrite a NUL byte because the check at lines 1115 and 1123
      would've jumped to verify when a NUL byte would be encountered.
      Therefore, the IS_UNC_PATH branch cannot overwrite a NUL byte, so
      the NUL byte we know we already got stays in place.
  - The else branch:
    ° We know the path length is at least 2 due to IS_ABSOLUTE_PATH.
      That means the earliest NUL byte can be at index 2, which can be
      overwritten on line 1133. We fix this by adding one byte write if
      the length is 2.

All uses of resolved_path in lines 1139-1141 have a NUL byte at the end
now.
Lines 1154-1164 do a bunch of post-processing but line 1164 will make
sure resolved_path still ends in a NUL byte.

So therefore I propose to remove the huge memset, and add a single byte
write in that one else branch I mentioned earlier.

Looking at Callgrind, the instruction count before this patch for 200
requests is 14,264,569,942; and after the patch it's 14,129,358,195
(averaged over a handful of runs).
2023-04-12 21:28:53 +02:00
Alex Dowad 6df7557e43 mb_parse_str, mb_http_input, and mb_convert_variables use fast text conversion code for automatic encoding detection
For mb_parse_str, when mbstring.http_input (INI parameter) is a list of
multiple possible text encodings (which is not the case by default),
this new implementation is about 25% faster.

When mbstring.http_input is a single value, then nothing is changed.
(No automatic encoding detection is done in that case.)
2023-04-12 19:57:52 +02:00
Niels Dossche 6ebd08bb33 Optimize HT_HASH_RESET (#11059)
Commit d835de1993 added support for AVX2 in hash table initialization
code. The same kind of code also occurs for HT_HASH_RESET. However, this
place was forgotten in that patch. That is unfortunate, because a loop
is just when there may be the most benefit from this SIMD sequence.
Furthermore, the NEON special handling exists in the initialization code
but is also missing from HT_HASH_RESET, so add this as well.
2023-04-12 19:14:54 +02:00
George Peter Banyard aae20cd119 ext/phar: Fix recently introduced potential NULL dereferencement segfaults (#11065) 2023-04-12 17:05:03 +01:00
Derick Rethans 71ff744a29 Merge branch 'PHP-8.2' 2023-04-12 11:39:11 +01:00
Derick Rethans d3f82f30b7 Merge branch 'PHP-8.1' into PHP-8.2 2023-04-12 11:39:02 +01:00
Derick Rethans 884eb4bba6 Merge remote-tracking branch 'derickr/fixed-broken-date-time-tests' into PHP-8.1 2023-04-12 11:36:39 +01:00
Niels Dossche c0c80b5b74 Merge branch 'PHP-8.2'
* PHP-8.2:
  [ci skip] UPDATE NEWS
2023-04-11 22:19:20 +02:00
Niels Dossche 805f21b9bf Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] UPDATE NEWS
2023-04-11 22:18:59 +02:00
Niels Dossche 450fcc4c9b [ci skip] UPDATE NEWS
ElliotNB helped me a lot debugging this by constantly testing the
patches. It is only fair that he is mentioned too, as I couldn't have
solved it without his help.
2023-04-11 22:17:47 +02:00
Ilija Tovilo 86ffde3c38 Improve ini number handling with INI_SCANNER_TYPED
Fixes GH-11010
Closes GH-11014
2023-04-11 18:54:11 +02:00
Jakub Zelenka 471dcf6e40 Merge branch 'PHP-8.2' 2023-04-11 12:49:11 +01:00
Jakub Zelenka d638c0d1e3 Merge branch 'PHP-8.1' into PHP-8.2 2023-04-11 12:48:23 +01:00
Jakub Zelenka 4be6435c9f Use curl from brew on MacOS CI
This fixes issue in curl ext SSL client cert setting test.

Closes GH-11056
2023-04-11 12:46:25 +01:00
George Peter Banyard ad997987dd ext/curl: Protocol should be a case insensitive check (#11052)
Minor drive-by refactoring to use the new API
2023-04-11 11:45:05 +01:00
Dmitry Stogov 0660fb5282 Merge branch 'PHP-8.2'
* PHP-8.2:
  Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048)
2023-04-10 23:25:42 +03:00
Dmitry Stogov e14ac1caee Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048)
2023-04-10 23:25:08 +03:00
Dmitry Stogov 0c65b396d6 Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048) 2023-04-10 23:19:17 +03:00
Alex Dowad 0bd826af39 Merge branch 'PHP-8.2'
* PHP-8.2:
  Add more details in UPGRADING on mb_check_encoding changes
2023-04-10 19:47:32 +02:00
Alex Dowad 7cef7cb0ee Add more details in UPGRADING on mb_check_encoding changes 2023-04-10 19:47:03 +02:00
Alex Dowad a62d192ede Add additional note on mb_encode_mimeheader in UPGRADING 2023-04-10 19:43:40 +02:00
Alex Dowad aa51871adc Add more details to NEWS on mb_detect_encoding; also include in UPGRADING 2023-04-10 19:43:05 +02:00
Alex Dowad d64c7184d4 Remove unneeded occurrences of my name in UPGRADING
In NEWS, each 'news item' is suffixed with the name of the developer
who implemented the change. When adding entries to UPGRADING, I used
the same format as NEWS, without thinking about it much. However, it
has come to my attention that the standard format for entries in
UPGRADING does not include the developer's name.
2023-04-10 19:35:35 +02:00
Ilija Tovilo c4a1100f19 Fix unevaluated rhs of class constant fetch in constant expression (#11047)
Fixes oss-fuzz #57821
2023-04-10 16:41:43 +02:00
George Peter Banyard 4082d425a9 ext/phar: Remove duplicate cleaning-up code 2023-04-10 13:23:08 +01:00
George Peter Banyard a72778b45d ext/phar: Prevent unnecessary known string length computation
Closes GH-11033
2023-04-10 13:23:08 +01:00
George Peter Banyard b9af98092c Add case insensitive versions of the zend_string_starts_with_* APIs (#11032) 2023-04-10 12:35:52 +01:00
David CARLIER 6c532df705 ext/sockets adding FreeBSD's SO_REUSEPORT_LB constant.
SO_REUSEPORT_LB is, in fact, closer to the classical Linux's SO_REUSEPORT.

Close GH-11038
2023-04-08 17:35:10 +01:00
George Peter Banyard 421c56dda2 Use zend_string for DBA path (#10698) 2023-04-08 17:03:28 +01:00
Niels Dossche 115afeedac Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c
2023-04-08 16:47:05 +02:00
Niels Dossche 9261ff7ba9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c
2023-04-08 16:42:52 +02:00
Niels Dossche 51faf04dbd Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c
The TSRM keeps a hashtable mapping the thread IDs to the thread resource pointers.
It's possible that the thread disappears without us knowing, and then another thread
gets spawned some time later with the same ID as the disappeared thread.
Note that since it's a new thread the TSRM key pointer and cached pointer will be NULL.

The Apache request handler `php_handler()` will try to fetch some fields from the SAPI globals.
It uses a lazy thread resource allocation by calling `ts_resource(0);`.
This allocates a thread resource and sets up the TSRM pointers if they haven't been set up yet.

At least, that's what's supposed to happen. But since we are in a situation where the thread ID
still has the resources of the *old* thread associated in the hashtable,
the loop in `ts_resource_ex` will find that thread resource and assume the thread has been setup
already. But this is not the case since this thread is actually a new thread, just reusing the ID
of the old one, without any relation whatsoever to the old thread.
Because of this assumption, the TSRM pointers will not be setup, leading to a
NULL pointer dereference when trying to access the SAPI globals.

We can easily detect this scenario: if we're in the fallback path, and the pointer is NULL,
and we're looking for our own thread resource, we know we're actually reusing a thread ID.
In that case, we'll free up the old thread resources gracefully (gracefully because
there might still be resources open like database connection which need to be
shut down cleanly). After freeing the resources, we'll create the new resources for
this thread as if the stale resources never existed in the first place.
From that point forward, it is as if that situation never occurred.
The fact that this situation happens isn't that bad because a child process containing
threads will eventually be respawned anyway by the SAPI, so the stale thread resources
won't remain forever.

Note that we can't simply assign our own TSRM pointers to the existing
thread resource for our ID, since it was actually from a different thread
(just with the same ID!). Furthermore, the dynamically loaded extensions
have their own pointer, which is only set when their constructor is
called, so we'd have to call their constructor anyway...
I also tried to call the dtor and then the ctor again for those resources
on the pre-existing thread resource to reuse storage, but that didn't work properly
because other code doesn't expect something like that to happen, which breaks assumptions,
and this in turn caused Valgrind to (rightfully) complain about memory bugs.

Note 2: I also had to fix a bug in the core globals destruction because it
always assumed that the thread destroying them was the owning thread,
which on TSRM shutdown isn't always the case. A similar bug was fixed
recently with the JIT globals.

Closes GH-10863.
2023-04-08 16:34:07 +02:00
Derick Rethans e67bb14ab4 Fixed tests and remove the XFAIL 'Various bugs exist'. They did, but they were in the tests 2023-04-07 23:50:55 +01:00
Jakub Zelenka 7de83e2736 Merge branch 'PHP-8.2' 2023-04-07 12:29:46 +01:00
Jakub Zelenka 0b4f2fc9e8 Merge branch 'PHP-8.1' into PHP-8.2 2023-04-07 12:29:23 +01:00
Jakub Zelenka ebb3213f79 Add FPM FCGI env Apache handler UDS test 2023-04-07 12:28:42 +01:00
Niels Dossche ede8adb2e2 Fix GH-11016: Heap buffer overflow in ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER (#11021)
Not enough space was reserved for the packed resulting array because of
some confusion in the meaning of nr of used slots vs nr of elements.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-06 21:55:11 +02:00
Niels Dossche 2ef1930ad3 Fix number of elements after packed hash filling (#11022)
After a hash filling routine the number of elements are set to the fill
index. However, if the fill index is larger than the number of elements,
the number of elements are no longer correct. This is observable at
least via count() and var_dump(). E.g. the attached test case would
incorrectly show int(17) instead of int(11).

Solve this by only increasing the number of elements by the actual
number that got added. Instead of adding a variable that increments per
iteration, I wanted to save some cycles in the iteration and simply
compute the number of added elements at the end.

I discovered this behaviour while fixing GH-11016, where this filling
routine is easily exposed to userland via a specialised VM path [1].
Since this seems to be more a general problem with the macros, and may
be triggered outside of the VM handlers, I fixed it in the macros
instead of modifying the VM to fixup the number of elements.

[1] https://github.com/php/php-src/blob/b2c5acbb010f4bbc7ea9b53ba9bc81d672dd0f34/Zend/zend_vm_def.h#L6132-L6141
2023-04-06 21:54:59 +02:00
Jakub Zelenka f17cf2ed63 Merge branch 'PHP-8.2' 2023-04-06 16:01:13 +01:00
Jakub Zelenka 1ca1858f31 Merge branch 'PHP-8.1' into PHP-8.2 2023-04-06 16:00:48 +01:00