Commit graph

19515 commits

Author SHA1 Message Date
Ilija Tovilo
bbd9732f83
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-05-01 09:47:14 +09: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
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
Tim Düsterhus
00d4390ea1
Free the trampoline when deprecation on materializing __callStatic() of trait throws (#17729)
Fixes php/php-src#17728
2025-02-07 10:53:14 +01:00
Arnaud Le Blanc
24b191a4de
Fix ReflectionProperty::getRawValue() and related methods for properties overridden with hooks
`new Reflectionproperty($scope, $propName)` keeps a reference to the
zend_property_info of $propName declared in $scope. In getRawValue() and
related methods, we use this reference to check whether the property is hooked.

Calling `new ReflectionProperty($scope, $propName)->getRawValue($object)` is
equivalent to the expression $object->$propName from scope $scope (except that
it bypasses hooks), and thus may access an overridden property (unless the
original is private). This property may have hooks and different flags.

Here I fetch the effective property info before checking for hooks and
property flags.

Fixes GH-17713
Closes GH-17714
2025-02-07 10:49:02 +01:00
Tim Düsterhus
e13d25eb84
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Disallow calls to abstract `__call()` / `__callStatic()` (#17719)
2025-02-07 09:37:28 +01:00
Tim Düsterhus
0607b663d3
Disallow calls to abstract __call() / __callStatic() (#17719)
Fixes php/php-src#17718
2025-02-07 09:36:33 +01:00
Ilija Tovilo
ab6977d36c
Fix segfault when assigning to backing value by-ref from hook
Fixes oss-fuzz #391975641
Closes GH-17620
2025-02-05 18:06:05 +01:00
Niels Dossche
c7d3c5fcb1
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix fallback paths in fast_long_{add,sub}_function
2025-02-03 22:40:41 +01:00
Niels Dossche
7e06a81bbd
Fix fallback paths in fast_long_{add,sub}_function
This was asked to be checked in https://github.com/php/php-src/pull/17472#issuecomment-2591325036

There are 2 issues:
1) The UB in the if can overflow, and can be fixed by using zend_ulong
   for the sum/sub.
2) fast_long_sub_function() has a problem when result aliases.
   This is fixed in the same way as fast_long_add_function() works.

Closes GH-17666.
2025-02-03 22:38:00 +01:00
Tim Düsterhus
7eaa9f0478
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  zend_execute: Suppress values in `UnhandledMatchError` for `zend.exception_ignore_args=1` (#17619)
2025-01-31 10:21:32 +01:00
Tim Düsterhus
f8b57ff1bf
zend_execute: Suppress values in UnhandledMatchError for zend.exception_ignore_args=1 (#17619)
Fixes php/php-src#17618.
2025-01-31 10:19:49 +01:00
Ilija Tovilo
4f91af38cc
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix stack overflow detection for variable compilation
2025-01-29 23:28:16 +01:00
Ilija Tovilo
333f5dd848
Fix stack overflow detection for variable compilation
Closes GH-17623
2025-01-29 23:27:27 +01:00
Jakub Zelenka
c4b678fa70
PHP-8.3 is now for PHP 8.3.18-dev 2025-01-28 19:45:52 +01:00
Calvin Buckley
ef2c371f13
PHP-8.4 is now for PHP 8.4.5-dev 2025-01-28 13:27:39 -04:00
Tim Düsterhus
f37b165403
Fix #[\Deprecated] for __call() and __callStatic() (#17592)
* Fix `#[\Deprecated]` for `__call()` and `__callStatic()`

Fixes php/php-src#17597.

* Do not duplicate the `attributes` table in `zend_get_call_trampoline_func()`
2025-01-27 13:41:41 +01:00