Commit graph

19529 commits

Author SHA1 Message Date
Niels Dossche
6b795f64a5
Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
The trait handling for property hooks in preloading did not exist, we
add a check to skip trait clones and we add the necessary code to update
the op arrays.

Closes GH-18586.
2025-05-19 19:21:53 +02:00
Niels Dossche
08cba2dcc1
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix OSS-Fuzz #418106144
  Fix OSS-Fuzz #417078295
2025-05-19 19:07:17 +02:00
Niels Dossche
98cb17f4fd
Fix OSS-Fuzz #418106144
The VM assumes that an exception must be handled when the AST evaluation
returns FAILURE. However, the comparison functions always return SUCCESS
even if an exception happened. This can be fixed in
zend_ast_evaluate_inner() or we can make is_smaller_function() etc check
for the exception. I chose the former to avoid impact or API breaks.
Perhaps in the future the comparison functions should either return void
or return whether an exception happened, as to be not misleading.

Closes GH-18589.
2025-05-19 19:05:32 +02:00
Niels Dossche
46ac878f6a
Fix OSS-Fuzz #417078295
If the variable_ptr and fetched value are the same or overlap, then we
get a UAF. Prevent this by delaying destruction.

Closes GH-18588.
2025-05-19 19:04:58 +02:00
Levi Morrison
59e6165fa6
Merge branch 'PHP-8.3' into PHP-8.4 2025-05-19 09:53:15 -06:00
Levi Morrison
35455b17be
fix: dangling opline in ZEND_INIT_ARRAY (#18578)
This causes problems if an allocation profiler decides to walk the
stack, or if the engine itself OOMs on this opcode, and it tries to
print file and line information.
2025-05-19 09:45:28 -06:00
David Carlier
68abc19229
Follow-up on GH-18577, adjust new test due to change on nested objects. 2025-05-17 12:46:27 +01:00
David Carlier
e4e71215d6
Merge branch 'PHP-8.3' into PHP-8.4 2025-05-17 12:45:13 +01:00
David Carlier
88d6e7c238
fix regex typo for GH-18577 new test 2025-05-17 12:44:57 +01:00
David Carlier
a7884250b1
Merge branch 'PHP-8.3' into PHP-8.4 2025-05-17 11:20:39 +01:00
David Carlier
4dcbd24bad
GH-18572: infinite stack recursion in fallback object comparison.
With nested objects and recursive comparisons, it is for now unavoidable
to have a stack overflow we do some early damage control attempt early
on with zend.max_allowed_stack_size check but ultimately more a band-aid
than a definitive solution.

close GH-18577
2025-05-17 11:20:16 +01:00
Ilija Tovilo
386ab1dad2
Revert "Fix infinite recursion on deprecated attribute evaluation"
This reverts commit 272f7f75e2.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
2025-04-30 20:52:56 +02:00
Saki Takamachi
33b977e36b
PHP-8.4 is now for PHP 8.4.8-dev 2025-04-22 22:23:08 +09:00
Eric Mann
2852177f4d
PHP-8.3 is now for PHP 8.3.22-dev 2025-04-22 06:09:24 -07:00
Niels Dossche
1a1a83f1fc
Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
On win64, xmm6-xmm15 are preserved registers, but the prologues and
epilogues of JITted code don't handle these. The issue occurs when
calling into the JIT code again via an internal handler
(like call_user_func). Therefore, we want to save/restore xmm registers
upon entering/leaving execute_ex. Since MSVC x64 does not support inline
assembly, we create an assembly wrapper around the real execute_ex
function.
The alternative is to always save/restore these xmm registers into the
fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register
8 to 15. However, there we can use inline asm to fix this.

Closes GH-18352.
2025-04-21 13:15:43 +02:00
Ilija Tovilo
6d458caefe
Fix prop info fetching from prop slot with added hooks
Fixes GH-18268
Closes GH-18271
2025-04-08 18:45:26 +02:00
Arnaud Le Blanc
26f5009e91
Fix lazy proxy calling magic methods twice
Fixes GH-18038
Closes GH-18039
2025-03-27 16:17:13 +01:00
Ilija Tovilo
272f7f75e2
Fix infinite recursion on deprecated attribute evaluation
Fixes GH-17711
Fixes GH-18022
Closes GH-17712
2025-03-26 23:39:38 +01:00
Jakub Zelenka
b57f425cfe
PHP 8.3 is now for PHP 8.3.21-dev 2025-03-25 22:09:16 +01:00
Calvin Buckley
9d0c492d30
Bump for 8.4.7-dev 2025-03-25 16:38:46 -03:00
Ilija Tovilo
d5bdf8f508
Fix segfault when evaluating const expr default value of child prop with added hooks
Introduced by GH-17870. Not adding a NEWS entry since this is fixed in
the same version.

Fixes oss-fuzz #403816122
Closes GH-18098
2025-03-23 16:35:04 +01:00
Niels Dossche
d765b60778
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table
2025-03-21 13:57:16 +01:00
Niels Dossche
2ec8d37eb4
Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table
If there's a try-finally where the try_op starts on a basic block with a
single JMP, and the JMP optimization causes that basic block to become
unreachable, then we update try_op.
In this case, there is no catch_op, so try_op is erroneously set to 0,
we should instead set it to `b->start`.

Closes GH-18110.
2025-03-21 13:56:31 +01:00
Niels Dossche
8d7cb8cc21
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17836: zend_vm_gen.php shouldn't break on Windows line endings
2025-03-21 11:51:05 +01:00
Daniel Scherzer
fa3c1c81d5
Fix GH-17836: zend_vm_gen.php shouldn't break on Windows line endings
Closes GH-18121.
2025-03-21 11:50:34 +01:00
Niels Dossche
e98e4e39a3
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fixed bug GH-13193 again
2025-03-21 11:48:16 +01:00
Niels Dossche
447d143b9d
Fixed bug GH-13193 again
Closes GH-13193.
2025-03-21 11:47:52 +01:00
Ilija Tovilo
56841998de
Fix IN_ARRAY optimization
in_array() calls are compiled to frameless calls. Adjust the
optimization appropriately. Luckily, frameless opcodes simplify the
optimization quite a bit.

Fixes GH-18050
Closes GH-18066
2025-03-18 13:42:53 +01:00
Niels Dossche
4fd9992561
Fix OSS-Fuzz #403308724
Because simple hooks can be nested without starting a new context, we
need to restore the old property info in case of nested hooks.

Closes GH-18074.
2025-03-16 13:42:40 +01:00
Arnaud Le Blanc
4b9c72f329
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Destroy temporary module classes in reverse order
2025-03-14 10:49:10 +01:00
Arnaud Le Blanc
1c182674b0
Destroy temporary module classes in reverse order
We destroy classes of dl()'ed modules in clean_module_classes(), during
shutdown. Child classes of a module use structures of the parent class (such as
inherited properties), which are destroyed earlier, so we have a use-after-free
when destroying a child class.

Here I destroy classes in reverse order, as it is done in zend_shutdown() for
persistent classes.

Fixes GH-17961
Fixes GH-15367
2025-03-14 10:45:17 +01:00
Eric Mann
517d7d909d
PHP-8.3 is now for PHP-8.3.20-dev 2025-03-12 06:34:55 -07:00
Jakub Zelenka
6976fb6ba7
Merge branch 'PHP-8.3' into PHP-8.4 2025-03-11 22:23:09 +01:00
Ilija Tovilo
ef2c459941
Use-after-free for ??= due to incorrect live-range calculation
Fixes GHSA-rwp7-7vc6-8477
2025-03-11 22:10:21 +01:00
Ilija Tovilo
8254e8de31
Fix lazy proxy calling set hook twice
Writing to an uninitialized lazy proxy will initialize the underlying
object and then call zend_std_write_property() on it. If this happens
inside a hook, zend_std_write_property() should not call the hook again
but directly write to the property slot. This didn't previously work
because zend_should_call_hook() would compare the parent frame
containing the proxy to the underlying object. This is now handled
explicitly.

Fixes GH-18000
Closes GH-18001
2025-03-08 12:38:27 +01:00
Ilija Tovilo
9acfe6e11c
Fix skipped lazy init on primed SIMPLE_WRITE
Go through the normal assignment path, which includes an IS_UNDEF check.

Fixes GH-17998
Closes GH-17999
2025-03-08 12:32:18 +01:00
Ilija Tovilo
868959350f
Fix incorrect handling of hooked props without get hook in get_object_vars()
Fixes GH-17988
Closes GH-17997
2025-03-08 12:27:28 +01:00
Niels Dossche
38e8725bec
Fix GH-17941: Stack-use-after-return with lazy objects and hooks
zend_std_write_property() can return the variable pointer, but the code
was using a local variable, and so a pointer to a local variable could
be returned. Fix this by using the value pointer instead of the backup
value was written.
This can be more efficient on master by using the safe_assign helper.

Closes GH-17947.
2025-03-08 00:00:01 +01:00
Niels Dossche
ee4a9a4a7c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:37:07 +01:00
Niels Dossche
ce8ab5f16a
Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00
Tim Düsterhus
2e999bad34
Fix ReflectionFunction::isDeprecated() for materialized __call() (#17914)
* Fix `ReflectionFunction::isDeprecated()` for materialized `__call()`

Fixes php/php-src#17913

* NEWS
2025-02-27 14:48:08 +01:00
Ilija Tovilo
376e90fbf2
Fix circumvented added hooks in JIT
The following code poses a problem in the JIT:

```php
class A {
    public $prop = 1;
}

class B extends A {
    public $prop = 1 {
        get => parent::$prop::get() * 2;
    }
}

function test(A $a) {
    var_dump($a->prop);
}

test(new B);
```

The JIT would assume A::$prop in test() could be accessed directly
through OBJ_PROP_NUM(). However, since child classes can add new hooks
to existing properties, this assumption no longer holds.

To avoid introducing more JIT checks, a hooked property that overrides a
unhooked property now results in a separate zval slot that is used
instead of the parent slot. This causes the JIT to pick the slow path
due to an IS_UNDEF value in the parent slot.

zend_class_entry.properties_info_table poses a problem in that
zend_get_property_info_for_slot() and friends will be called using the
child slot, which does not store its property info, since the parent
slot already does. In this case, zend_get_property_info_for_slot() now
provides a fallback that will iterate all property infos to find the
correct one.

This also uncovered a bug (see Zend/tests/property_hooks/dump.phpt)
where the default value of a parent property would accidentally be
inherited by the child property.

Fixes GH-17376
Closes GH-17870
2025-02-26 21:26:00 +01:00
Ilija Tovilo
e0c69dde02
Fix accidentally inherited default value in overridden virtual properties
Discovered when working on GH-17376.
2025-02-26 21:16:58 +01:00
Ilija Tovilo
7a55116f12
Fix property hook backing value access in multi-level inheritance
Discovered by Niels when testing GH-17376.
2025-02-26 20:49:07 +01:00
Eric Mann
00a772bf94
PHP-8.3 is now for PHP 8.3.19-dev 2025-02-25 09:20:39 -08:00
Saki Takamachi
1ec469d116
PHP-8.4 is now for PHP 8.4.6-dev 2025-02-26 00:02:20 +09:00
Niels Dossche
2542357b6d
Fix GH-17866: zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4
This regressed in GH-17592.
The function is with its attributes HashTable* is copied in
zend_get_closure_invoke_method() but its refcount is not increased.
This caused a crash in the Symfony demo page.

Closes GH-17880.
2025-02-24 21:39:55 +01:00
Daniel Scherzer
c0857e0d8a
Fix GH-17916: Final abstract properties should error
Closes GH-17917.
2025-02-24 20:17:41 +01:00
Bob Weinand
53fa98ecd3
Fix GH-17715: Handle preloaded internal function runtime cache (#17835)
This solely affects the builtin enum functions currently.

Given that these are stored in SHM, we cannot simply hardwire a pointer into the internal function runtime cache on NTS too, but have to use a MAP_PTR (like on ZTS).
Now, by design, the runtime cache of internal functions no longer is reset between requests, hence we need to store them explicitly as static runtime cache.

On NTS builds we cannot trivially move the pointers into CG(internal_run_time_cache) as they're directly stored on the individual functions (on ZTS we could simply iterate the static map_ptrs).
Hence, we have the choice between having opcache managing the internal run_time_cache for its preloaded functions itself or realloc CG(internal_run_time_cache) and iterate through all functions to assign the new address. We choose the latter for simplicity and initial speed.
2025-02-24 14:35:47 +01:00
Tim Düsterhus
041036960c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Free the trampoline when deprecation on materializing `__callStatic()` of trait throws (#17729)
2025-02-07 10:53:31 +01:00