Commit Graph

18647 Commits

Author SHA1 Message Date
Ilija Tovilo
2e6d34c72e
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix use-after-free of constant name
2023-10-11 11:52:11 +02:00
Ilija Tovilo
53dbb760da
Fix use-after-free of constant name
The constant name is usually interend. Without opcache, compilation always
interns strings. Without opcache, compilation does not intern (new) strings, but
persisting of script does. If a script is not stored in shm the constant name
will not be interned.

The building of enum backing stores was missing a addref for the constant name,
leading to a double-free when releasing constants and backing stores of enums.

Fixes GH-12366
Closes GH-12405
2023-10-11 11:49:40 +02:00
Pierrick Charron
2642a08697
PHP-8.2 is now for PHP 8.2.13-dev 2023-10-10 11:45:26 -04:00
Ilija Tovilo
4ba5699903
Fix invalid returned opcode for memoized expressions
Closes GH-12345
2023-10-03 14:01:43 +02:00
Dmitry Stogov
9bfdb4cf4b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:36 +03:00
Dmitry Stogov
101bd1b199 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:22 +03:00
Dmitry Stogov
54452b4811 Fixed GH-12262: Tracing JIT assertion crash when using phpstan 2023-10-03 13:22:33 +03:00
Niels Dossche
04a2a42f2a Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2023-09-30 01:27:29 +02:00
Niels Dossche
0f5b382528 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2023-09-30 01:27:06 +02:00
Niels Dossche
643c4ba417 Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
Although it passes CI on 8.1, it causes CI failures in the JIT on 8.2 and
higher.
See https://github.com/php/php-src/actions/runs/6357716718/job/17269225001

This reverts commit e72fc12058.
2023-09-30 01:25:48 +02:00
Niels Dossche
fa2d556fcd Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:11:31 +02:00
Niels Dossche
d7a7309b53 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:10:35 +02:00
Niels Dossche
e72fc12058 Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
This test triggers narrowing for two ops: first ZEND_ADD_ARRAY_ELEMENT,
and then ZEND_ASSIGN.

The type inference happens in the following order:
1) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080 (packed flag is set),
   arr_type=0 at this point because it hasn't been set by ZEND_INIT_ARRAY yet.
2) The ZEND_INIT_ARRAY infers type 0x40804080
3) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080, arr_type=0x40804080,
   which does not have the packed flag set while the existing result of
   ZEND_ADD_ARRAY_ELEMENT has the packed flag set.

This seems to occur because of the phi node introduced by the while
loop. If I remove the loop the problem goes away.

As Arnaud noted, this seems to be caused by a too wide type inference
for arr_type==0. We should keep the invariant that if x>=y then
key_type(x) >= key_type(y).
If we write the possible results down in a table we get:

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
HASH_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH
PACKED_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
HASH || PACKED	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
0		-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
```

As we can see, `HASH_ONLY > 0` but
`MAY_BE_ARRAY_NUMERIC_HASH < MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED`,
which violates the invariant.
Instead if we modify the zero case to have MAY_BE_ARRAY_NUMERIC_HASH instead,
we get the following table which satisfies the invariant.

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
HASH_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH
PACKED_ONLY	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
HASH || PACKED	-> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
0		-> MAY_BE_ARRAY_NUMERIC_HASH
```

Broke in 1ffbb73.
Closes GH-10294.
2023-09-30 00:08:32 +02:00
Levi Morrison
8fb51d4fe4
Set func pointer to null in Closure __invoke (#12275) 2023-09-25 08:27:23 -06:00
David Carlier
639bcb4078 Merge branch 'PHP-8.2' into PHP-8.3 2023-09-18 17:46:28 +01:00
David Carlier
c39d4481c5 Merge branch 'PHP-8.1' into PHP-8.2 2023-09-18 17:46:11 +01:00
Florian Sowade
910f579f14 Fix GH-12207 memory leak of doc blocks of static properties
When declaring the same static property with a doc block in a class and in a trait,
the doc block of the property in the class is leaked. While at it, possibly fix doc
 comment for internal classes.

Close GH-12238
2023-09-18 17:44:47 +01:00
George Peter Banyard
0b614a6c2b
Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
Closes GH-12202
2023-09-17 15:49:46 +01:00
Tim Düsterhus
d344fe06a2
Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
Fixes GH-12189

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-09-15 14:57:10 +02:00
Tim Düsterhus
0e9d658dd2
Add abstract __construct() test for #[\Override] (024.phpt) 2023-09-14 12:58:08 +02:00
Ben Ramsey
c1cf0026e5
PHP-8.1 is now for PHP 8.1.25-dev 2023-09-12 16:21:51 -05:00
Sergey Panteleev
5c1f746716
PHP-8.2 is now for PHP 8.2.12-dev 2023-09-12 14:53:56 +03:00
Ilija Tovilo
011071a3b3
Improve invalid cpp modifier message
The ZEND_MODIFIER_TARGET_CPP should really have been called _PARAM, but we
shouldn't break API at this point.

Fixes GH-12069
Closes GH-12175
2023-09-11 16:23:43 +02:00
Ilija Tovilo
214afe0d96
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:36:22 +02:00
Ilija Tovilo
1c93cdcea4
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:35:51 +02:00
Ilija Tovilo
5286bab392
[skip ci] Skip arginfo_zpp_mismatch on asan
These tests intermittently crash asan. It might be due to some function invoking
dl(), which is known to crash lsan. It might also be something else, the version
of asan shipped with ubuntu 22.04 is flaky.
2023-09-11 11:32:34 +02:00
Máté Kocsis
45c7e3b06b
Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
Closes GH-12136
2023-09-10 22:40:50 +02:00
Ilija Tovilo
c2bb9bc0df
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:09 +02:00
Ilija Tovilo
fa9cef8b47
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:25:43 +02:00
Ilija Tovilo
748adf18fc
Fix zend_separate_if_call_and_write for FUNC_ARGs
Fixes GH-12102
Closees GH-12140
2023-09-07 14:25:11 +02:00
George Peter Banyard
8a392eddf9 Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
Reorder when we assign the property value to NULL which is identical to
a3a3964497

Just for the declared property case instead of dynamic.

Closes GH-12114
2023-09-05 10:40:02 +01:00
George Peter Banyard
d7273c5963 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:36:16 +01:00
George Peter Banyard
c672a06954 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:27:33 +01:00
ju1ius
da7a66d647 Prevents double call to internal iterator rewind handler
Closes GH-12060

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-09-05 10:26:19 +01:00
Dmitry Stogov
b4ce171aa2 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:47 +03:00
Dmitry Stogov
ab6d564a7e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:22 +03:00
Dmitry Stogov
f1f608bf53 Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash) 2023-09-05 10:11:54 +03:00
Ilija Tovilo
baf74ed1a4
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:39 +02:00
Ilija Tovilo
6850a040f3
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:20 +02:00
Ilija Tovilo
af2110e664
Fix freeing of incompletely initialized closures
Addref to relevant fields before allocating any memory. Also only set/remove the
ZEND_ACC_HEAP_RT_CACHE flag after allocating memory.

Fixes GH-12073
Closes GH-12074
2023-09-04 15:35:39 +02:00
Niels Dossche
eee1617f38 Tweak behaviour of dynamic properties wrt error handlers
With the fix in https://github.com/php/php-src/pull/12114, the behaviour
would change for non-dynamic properties. Align the behaviour for dynamic
properties to be the same.

Closes GH-12117.
2023-09-03 18:27:21 +02:00
George Peter Banyard
013bb5769b Add tests for oss-fuzz-61469: Undef dynamic property in ++/-- unset in error handler
This was fixed as a consequence of a3a3964497

Closes GH-12011
2023-09-02 23:34:20 +01:00
Remi Collet
1f2cfd8009
ensure displays_errors is off (default) 2023-08-31 14:55:17 +02:00
George Peter Banyard
9b28e521d1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-11876: ini_parse_quantity() accepts invalid quantities
2023-08-30 21:23:10 +01:00
George Peter Banyard
d229a480ad Fix GH-11876: ini_parse_quantity() accepts invalid quantities
Closes GH-11910
2023-08-30 21:22:13 +01:00
Jakub Zelenka
2eb21b0b1e
Update API versions and numbers 2023-08-29 17:04:24 +01:00
Niels Dossche
a3a3964497 Fix oss-fuzz #61712: assertion failure with error handler during binary op
Because the error handler is invoked after the property is updated,
the error handler has the opportunity to remove it before the property
is returned.

Switching the order around fixes this issue. The comments mention that
the current ordering prevents overwriting the EG(std_property_info)
field in the error handler. EG(std_property_info) no longer exists as it
was removed in 7471c217. Back then a global was used to store the
returned property info, but as this is no longer the case there is no
longer a need to protect against overwriting a global.

Closes GH-12062.
2023-08-28 20:00:49 +02:00
Bob Weinand
b07a2d4714 Address CR comments
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Bob Weinand
cd53ce838a Track HashTableIterators for copy-on-write copies of HashTables
When executing a foreach ($ht as &$ref), foreach calls zend_hash_iterator_pos_ex() on every iteration. If the HashTable contained in the $ht variable is not the tracked HashTable, it will reset the position to the internal array pointer of the array currently in $ht.
This behaviour is generally fine, but undesirable for copy-on-write copies of the iterated HashTable. This may trivially occur when the iterated over HashTable is assigned to some variable, then the iterated over variable modified, leading to array separation, changing the HashTable pointer in the variable. Thus foreach happily restarting iteration.
This behaviour (despite existing since PHP 7.0) is considered a bug, if not only for the behaviour being unexpected to the user, also copy-on-write should not have trivially observable side-effects by mere assignment.

The bugfix consists of duplicating HashTableIterators whenever zend_array_dup() is called (the primitive used on array separation).
When a further access to the HashPosition through the HashTableIterators API happens and the HashTable does not match the tracked one, all the duplicates (which are tracked by single linked list) are searched for the wanted HashTable. If found, the HashTableIterator is replaced by the found copy and all other copies are removed.
This ensures that we always end up tracking the correct HashTable.

Fixes GH-11244.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Máté Kocsis
c934e24197 Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs 2023-08-26 21:35:31 +02:00