Commit graph

19606 commits

Author SHA1 Message Date
Niels Dossche
8b5231388c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-19065: Long match statement can segfault compiler during recursive SSA renaming
2025-08-11 23:05:50 +02:00
Niels Dossche
9b86533ce4
Fix GH-19065: Long match statement can segfault compiler during recursive SSA renaming
On some systems, like Alpine, the thread stack size is small by default.
The last step of SSA construction involves variable renaming that is
recursive, and also makes copies of their version of the renamed
variables on the stack. This combination causes a stack overflow during
compilation on Alpine. Triggerable for example with very long match
statements.

A stop-gap solution would be to use heap allocated arrays for the
renamed variable list, but that would only delay the error as increasing
the number of match arms increases the depth of the dominator tree, and
will eventually run into the same issue.

This patch transforms the algorithm into an iterative one.
There are two states stored in a worklist stack: positive numbers
indicate that the block still needs to undergo variable renaming.
Negative numbers indicate that the block and its dominated children are
already renamed. Because 0 is also a valid block number, we bias the
block numbers by adding 1.
To restore to the right variant when backtracking the "recursive" step,
we index into an array pointing to the different variable renaming
variants.

Closes GH-19083.
2025-08-11 23:05:21 +02:00
David Carlier
bd2766ce79
zend call stack fixing stack limit for macOs arm64.
8MB sounded a prudent size for older 10.9 macOs release, however
with newer mac with arm64, it triggers a stack overflow.

Cherry picks b320aabc5e (GH-13319) from PHP-8.4.
Closes GH-19390.
2025-08-07 08:38:40 +02:00
Ilija Tovilo
b3f4863373
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix circumvented type check with return by ref + finally
2025-08-01 00:36:28 +02:00
Ilija Tovilo
d0fad34230
Fix circumvented type check with return by ref + finally
Fixes GH-18736
Closes GH-19172
2025-08-01 00:35:48 +02:00
Ilija Tovilo
5d40592fe2
Fix stale nInternalPosition on rehashing
Since GH-13188 we're no longer immediately updating iterator positions when
deleting array elements. zend_hash_rehash() needs to adapt accordingly by
adjusting nInternalPosition for IS_UNDEF elements. This is already the case for
array iterators.

Fixes GH-19280
Closes GH-19323
2025-07-31 21:55:08 +02:00
Arnaud Le Blanc
781d77ac54
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Prevent throwing in running generator
2025-07-31 14:29:01 +02:00
Arnaud Le Blanc
6fa8a25a40
Prevent throwing in running generator
Generator::throw() on a running generator is not allowed. It throws "Cannot
resume an already running generator" when trying to resume the generator to
handle the provided exception.

However, when calling Generator::throw() on a generator with a non-Generator
delegate, we release the delegate regardless. If a Fiber was suspended in
the delegate, this causes use after frees when the Fiber is resumed.

Fix this by throwing "Cannot resume an already running generator" earlier.

Fixes GH-19326
Closes GH-19327
2025-07-31 14:26:41 +02:00
Arnaud Le Blanc
a430ee2dd2
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Prevent resumption of generator suspended in yield from
2025-07-31 08:46:06 +02:00
Arnaud Le Blanc
0406a55c92
Prevent resumption of generator suspended in yield from
Normally we prevent generators from being resumed while they are already
running, but we failed to do so for generators delegating to non-Generators. As
a result such generator can be resumed, terminated, which causes unexpected
results (crashes) later.

In gh19306.phpt in particular, the generator delegate It::getIterator() suspends
while being called by generator g(). We then resume g(), which throws while
trying to resume It::getIterator(). This causes g() and It::getIterator()
to be released. We then UAF when resuming the Fiber in It::getIterator().

Fix this by ensuring that generators are marked as running while they fetch
the next value from the delegate.

Fixes GH-19306
Closes GH-19315
2025-07-31 08:45:19 +02:00
Niels Dossche
a08df32f18
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-19303: Unpacking empty packed array into uninitialized array causes assertion failure
2025-07-30 22:48:59 +02:00
Niels Dossche
5bd5f352e5
Fix GH-19303: Unpacking empty packed array into uninitialized array causes assertion failure
Having an empty result array is not a problem, because zend_hash_extend()
will initialize it. Except it does not when the number of elements to add
equals 0, which leaves the array uninitialized and therefore does not
set the packed flag, causing the assertion failure.

Technically, removing the assert would also work and save a check.
On the other hand, this check could also prevent some real work to be
done and should be relatively cheap as we already have to compute the
sum anyway.

Closes GH-19318.
2025-07-30 22:47:11 +02:00
Arnaud Le Blanc
28ed4e6ec0
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Prevent operands from being released during comparison
2025-07-30 18:11:32 +02:00
Arnaud Le Blanc
bc4b6ce7a8
Prevent operands from being released during comparison
Fixes GH-19305
Closes GH-19309
2025-07-30 18:09:24 +02:00
Ilija Tovilo
138ebf481b
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix failed assertion with throwing __toString in binary const expr
2025-07-30 13:34:32 +02:00
Ilija Tovilo
80022c035b
Fix failed assertion with throwing __toString in binary const expr
Solve this with the same pattern as ZEND_AST_GREATER[_EQUAL].

Fixes OSS-Fuzz #434346548
Closes GH-19291
2025-07-30 13:34:01 +02:00
Ilija Tovilo
4bc5aa3531
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Coerce numeric string keys from iterators when argument unpacking
2025-07-22 17:47:56 +02:00
Ilija Tovilo
23ec35bf4a
Coerce numeric string keys from iterators when argument unpacking
Fixes GH-18581
Closes GH-19151
2025-07-22 17:46:34 +02:00
Bob Weinand
b13347be38
Fix GH-19044: Protected properties are not scoped according to their prototype (#19046)
* Fix GH-19044: Protected properties are not scoped according to their prototype

* Adjust after review

* Simplify to using prototype even for asymmetric visibility
2025-07-22 17:46:14 +02:00
Niels Dossche
c04f2d2d88
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add missing cc clobber
2025-07-22 12:43:21 +02:00
Niels Dossche
13c781f04d
Add missing cc clobber
Closes GH-19205.
2025-07-22 12:43:08 +02:00
Ilija Tovilo
c8cc23336d
Fix properties_info_table for abstract properties
Fixes GH-19053
Closes GH-19140

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2025-07-21 15:54:24 +02:00
David Carlier
f1a77c0198
Merge branch 'PHP-8.3' into PHP-8.4 2025-07-18 18:02:02 +01:00
Petr Sumbera
be09985c87
Fix GH-19169: ZEND_STATIC_ASSERT for -std=c++17
needs to define ZEND_STATIC_ASSERT to appropriate C++ static_assert
instead of the C version.
2025-07-18 18:00:24 +01:00
Jakub Zelenka
faf833bffc
PHP 8.3 is now for PHP-8.3.25-dev 2025-07-16 14:09:24 +02:00
Calvin Buckley
3d468a181a
PHP-8.4 is now for PHP 8.4.12-dev 2025-07-15 13:46:33 -03:00
Demon
2be3aa86f0
Zend: fix undefined symbol 'execute_ex' on Windows ARM64 #19064; ext/gd: fix emmintrin.h not found on Windows ARM64 2025-07-10 22:13:29 +02:00
Peter Kokot
ab6e73066b
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix -Wuseless-escape warnings emitted by re2c (#19050)
2025-07-07 09:51:50 +02:00
Peter Kokot
258fbd6bf9
Fix -Wuseless-escape warnings emitted by re2c (#19050)
re2c version 4 enabled some warnings by default. This fixes re2c code
for the `-Wuseless-escape` warnings.

There are two same issues reported.
Issue: GH-17523
Closes: GH-17204
2025-07-07 09:51:25 +02:00
Niels Dossche
1af7d8e547
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix OSS-Fuzz #428983568 and #428760800
2025-07-04 23:58:33 +02:00
Niels Dossche
4aac98f145
Fix OSS-Fuzz #428983568 and #428760800
Both these issues have the same root cause, their reproducer is
extremely similar so I don't duplicate the test.

If the parser invokes the lexer, and the lexer fails, it could've
allocated a string which must be freed when the parser backs up.
The `%destructor` list is responsible for this but did not have an entry
for `fallback` yet. Solve the issue by adding such an entry.

Closes GH-19012.
2025-07-04 23:58:06 +02:00
Saki Takamachi
d5fe1bce63
PHP-8.4 is now for PHP 8.4.11-dev 2025-07-02 11:39:33 +09:00
Niels Dossche
5d590a1e87
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix OSS-Fuzz #427814456
2025-07-01 18:52:39 +02:00
Niels Dossche
91749844e6
Fix OSS-Fuzz #427814456
The first warning may trigger an error handler, destroying the operand
and its string. So we need to protect the string in that case.
Care was taken to avoid unnecessary refcounts and to avoid touching the
hot code path.

Closes GH-18951.
2025-07-01 18:50:41 +02:00
Shivam Mathur
a8bd3ba1bb
Merge branch 'PHP-8.3' into PHP-8.4 2025-06-25 03:22:43 +05:30
Shivam Mathur
ac15486ae0
Fix CI for windows-2022
This is a continuation of GH-18927 to fix CI for windows-2022
2025-06-25 03:20:49 +05:30
Niels Dossche
f77c04d007
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix RCN violations in array functions
2025-06-24 23:29:50 +02:00
Niels Dossche
359a21f102
Fix RCN violations in array functions
When the array functions perform their operation in-place, the
`@refcount 1` annotation is wrong and causes a failure under
`ZEND_VERIFY_FUNC_INFO`.
The test file tests all functions that have the in-place optimization,
even those that didn't have the refcount annotation, just to prevent
future regressions.

Closes GH-18929.
2025-06-24 23:29:00 +02:00
Shivam Mathur
d2a30acf33
Merge branch 'PHP-8.3' into PHP-8.4 2025-06-25 02:01:59 +05:30
Shivam Mathur
dc79f4c8c6
Merge branch 'PHP-8.2' into PHP-8.3 2025-06-25 02:01:24 +05:30
Shivam Mathur
91f2458020
Merge branch 'PHP-8.1' into PHP-8.2 2025-06-25 02:00:11 +05:30
Shivam Mathur
6233dc6210
Switch to windows-2022 in CI (#18927)
* Switch to windows-2022 in CI

windows-2019 runner will be dropped by GitHub on 2025-06-30.

* xfail test cases that fail on windows-2022
2025-06-25 01:57:07 +05:30
Ilija Tovilo
fe504d3357
Fix leak when creating cycle in hook
This is necessary because the VM frees operands with the nogc variants. We
cannot just call gc_possible_root() because the object may no longer exist at
that point.

Fixes GH-18907
Closes GH-18917
2025-06-23 17:48:07 +02:00
Ilija Tovilo
0ee73ccbe5
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Track heap->real_size for USE_TRACKED_ALLOC
2025-06-20 14:51:20 +02:00
Ilija Tovilo
dfc4caa1e4
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Track heap->real_size for USE_TRACKED_ALLOC
2025-06-20 14:51:00 +02:00
Ilija Tovilo
7841c8a3df
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Track heap->real_size for USE_TRACKED_ALLOC
2025-06-20 14:49:47 +02:00
Ilija Tovilo
9cacc57350
Track heap->real_size for USE_TRACKED_ALLOC
real_size is returned by memory_get_usage(true), which previously returned 0.
Discovered in Symfony ConsumeMessagesCommandTest::testRunWithMemoryLimit()
through nightly.

Closes GH-18880
2025-06-20 14:48:47 +02:00
Niels Dossche
bb6263af60
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix use after free during shutdown destruction
2025-06-18 21:20:25 +02:00
Daniil Gentili
5cf3c2663b
Fix use after free during shutdown destruction
Closes GH-18834.
2025-06-18 21:20:03 +02:00
Eric Mann
50606f8569
PHP 8.3 is now for PHP 8.3.24-dev 2025-06-17 08:06:35 -07:00