1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

2046 Commits

Author SHA1 Message Date
Ilija Tovilo
6173a9a109 VAR|TMP overhaul (GH-20628)
The aim of this PR is twofold:

- Reduce the number of highly similar TMP|VAR handlers
- Avoid ZVAL_DEREF in most of these cases

This is achieved by guaranteeing that all zend_compile_expr() calls, as well as
all other compile calls with BP_VAR_{R,IS}, will result in a TMP variable. This
implies that the result will not contain an IS_INDIRECT or IS_REFERENCE value,
which was mostly already the case, with two exceptions:

- Calls to return-by-reference functions. Because return-by-reference functions
  are quite rare, this is solved by delegating the DEREF to the RETURN_BY_REF
  handler, which will examine the stack to check whether the caller expects a
  VAR or TMP to understand whether the DEREF is needed. Internal functions will
  also need to adjust by calling the zend_return_unwrap_ref() function.

- By-reference assignments, including both $a = &$b, as well as $a = [&$b]. When
  the result of these expressions is used in a BP_VAR_R context, the reference
  is unwrapped via a ZEND_QM_ASSIGN opcode beforehand. This is exceptionally
  rare.

Closes GH-20628
2026-01-31 19:44:56 +01:00
Arshid
d1c1a9fa82 [skip ci] Remove unused arg from zend_throw_incdec_ref_error() (GH-21081) 2026-01-30 18:58:25 +01:00
Ilija Tovilo
084e409694 Remove zend_exception_save() and zend_exception_restore()
These are leftovers from the pre-PHP-7.0 era. This also implicitly solves
GH-20564 by not clearing exceptions before entering the autoloader.

Closes GH-20256
Fixes GH-20564
2026-01-16 20:18:51 +01:00
Ilija Tovilo
8b4ef3a09f Fix FETCH_OBJ_UNSET IS_UNDEF result
UNSET_OBJ et al. do not expect to find IS_UNDEF results for IS_INDIRECT vars. To
solve this, return IS_NULL from FETCH_OBJ_UNSET when properties are
uninitialized. Do the same for FETCH_STATIC_PROP_IS, as we're otherwise copying
IS_UNDEF into the VAR result, which is not a valid value for VAR.

Fixes OSS-Fuzz #429429090
Closes GH-19160
2026-01-16 19:27:21 +01:00
Tim Düsterhus
0ab1f9f223 zend_execute: Remove unused scope parameter from zend_check_type() (#20937) 2026-01-15 19:59:31 +01:00
Bob Weinand
b95d2ee70a Merge branch 'PHP-8.5'
* PHP-8.5:
  Split the live-ranges of loop variables again (#20865)
2026-01-15 16:17:34 +01:00
Bob Weinand
c878380065 Merge branch 'PHP-8.4' of github.com:php/php-src into PHP-8.5
* 'PHP-8.4' of github.com:php/php-src:
  Split the live-ranges of loop variables again (#20865)
2026-01-15 16:15:29 +01:00
Bob Weinand
27ed48c0be Split the live-ranges of loop variables again (#20865)
* Fix use-after-free in FE_FREE with GC interaction

When FE_FREE with ZEND_FREE_ON_RETURN frees the loop variable during
an early return from a foreach loop, the live range for the loop
variable was incorrectly extending past the FE_FREE to the normal
loop end. This caused GC to access the already-freed loop variable
when it ran after the RETURN opcode, resulting in use-after-free.

Fix by splitting the ZEND_LIVE_LOOP range when an FE_FREE with
ZEND_FREE_ON_RETURN is encountered:
- One range covers the early return path up to the FE_FREE
- A separate range covers the normal loop end FE_FREE
- Multiple early returns create multiple separate ranges

* Split the live-ranges of loop variables again

b0af9ac733 removed the live-range splitting of foreach variables, however it only added handling to ZEND_HANDLE_EXCEPTION.
This was sort-of elegant, until it was realized in 8258b7731b that it would leak the return variable, requiring some more special handling.
At some point we added live tmpvar rooting in 52cf7ab8a2, but this did not take into account already freed loop variables, which also might happen during ZEND_RETURN, which cannot be trivially accounted for, without even more complicated handling in zend_gc_*_tmpvars() functions.

This commit also proposes a simpler way of tracking the loop end in loopvar freeing ops: handle it directly during live range computation rather than during compilation, eliminating the need for opcache to handle it specifically.
Further, opcache was using live_ranges in its basic block computation in the past, which it no longer does. Thus this complication is no longer necessary and this approach should be actually simpler now.

Closes #20766.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>

---------

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
Co-authored-by: Gustavo Lopes <mail@geleia.net>
2026-01-15 16:13:43 +01:00
Arnaud Le Blanc
626f3c3c7c Unify arg info representation for internal and user functions
The arg_info member of zend_function is now always a zend_arg_info*. Before,
it was a zend_internal_arg_info* on internal functions, unless the
ZEND_ACC_USER_ARG_INFO flag was set.

Closes GH-19022
2025-12-15 16:50:49 +01:00
Gina Peter Banyard
7815ab9b22 Zend: add const qualifiers when possible for _zend_execute_data.func related uses (#20263)
The initial motivation was to see if it is possible to make the `func` field of `_zend_execute_data` constant.

For various reasons, this is not possible, but the added `const` qualifiers during this exploration remain useful.
2025-10-29 13:22:56 +00:00
Gina Peter Banyard
f8656fae35 Zend: use uint32_t type instead of int for extended_value counter 2025-10-22 23:08:37 +01:00
Ilija Tovilo
292e0c2937 Add ce_flags2 & fn_flags2 (GH-19991) 2025-09-30 22:54:59 +02:00
Tim Düsterhus
c9b175992c Zend: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
ef1b5ae61b Zend: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Gina Peter Banyard
b4ed215299 core: Warn when non-representable floats are coerced to int (#19760)
RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int
2025-09-21 23:53:16 +01:00
Ilija Tovilo
025ac98c75 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix use-of-uninitialized-value in zend_get_arg_offset_by_name()
2025-09-17 15:56:46 +02:00
Ilija Tovilo
657dfc91f8 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix use-of-uninitialized-value in zend_get_arg_offset_by_name()
2025-09-17 15:56:35 +02:00
Ilija Tovilo
6eb3faef3b Fix use-of-uninitialized-value in zend_get_arg_offset_by_name()
Don't access fbc->op_array.refcount on internal function. Don't attempt to cache
ZEND_ACC_USER_ARG_INFO at all, which is only used in
zend_get_closure_invoke_method(). This may reuse arg_info from a temporary
closure, and hence caching would also be unsafe.

Also avoid populating the cache slot for variadic parameters, where the
ZEND_ACC_USER_ARG_INFO is set for the same reason.

Closes GH-19856
2025-09-17 15:54:35 +02:00
Niels Dossche
d6300a3065 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-19653: Closure named argument unpacking between temporary closures can cause a crash
2025-09-14 22:11:22 +02:00
Niels Dossche
a3d27aab03 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-19653: Closure named argument unpacking between temporary closures can cause a crash
2025-09-14 22:08:41 +02:00
Niels Dossche
22252954ef Fix GH-19653: Closure named argument unpacking between temporary closures can cause a crash
Due to user closures, the `fbc` address isn't unique if the memory address is reused.
We need to distinguish using a unique key, and we choose arg_info such
that it can be reused across different functions.

Closes GH-19654.
2025-09-14 22:07:36 +02:00
Daniel Scherzer
34a6e86282 [RFC] Allow #[\Deprecated] on traits (#19045)
https://wiki.php.net/rfc/deprecated_traits
2025-09-05 12:30:50 -07:00
Alexandre Daubois
49e3956b70 core: Deprecate using null as an array offset and when calling array_key_exists() (#19511)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
2025-09-04 22:12:24 +01:00
Gina Peter Banyard
8747e9ae18 Zend: Warn when destructuring non-array values (#19439)
RFC: https://wiki.php.net/rfc/warnings-php-8-5#destructuring_non-array_values
2025-08-29 16:06:34 +01:00
Gina Peter Banyard
105c1e9896 tree: use zend_str_has_nul_byte() API (#19336) 2025-07-31 23:57:27 +01:00
Tim Düsterhus
b43a7ac0e7 Zend: Make EG(fake_scope) a const zend_class_entry* (#19060) 2025-07-09 11:55:53 +02:00
Tim Düsterhus
59dd0f8a48 Zend: Use zend_bad_method_call() when cloning from the wrong scope (#18999) 2025-07-01 20:24:11 +02:00
Tim Düsterhus
1a18012be3 zend_vm_gen: Fix GET_OP*_OBJ_ZVAL_PTR_DEREF for ANY (#18746)
Fixes php/php-src#18745
2025-06-09 09:34:49 +02:00
DanielEScherzer
3f03f7ed3d [RFC] Add support for attributes on compile-time constants
https://wiki.php.net/rfc/attributes-on-constants
2025-04-29 11:53:09 -07:00
Niels Dossche
a32f491855 Remove cache slot from ZEND_VERIFY_TYPE and arg RECV opcodes (#18258) 2025-04-07 19:50:48 +02:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Tim Düsterhus
169a6c63f0 zend_execute: Remove useless refcounting in get_deprecation_suffix_from_attribute() (#18229) 2025-04-02 09:37:00 +02:00
Tim Düsterhus
5544be7018 RFC: Marking return values as important (#[\NoDiscard]) (#17599)
RFC: https://wiki.php.net/rfc/marking_return_value_as_important

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-02 09:35:29 +02:00
Niels Dossche
d95b9d6d32 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17736: Assertion failure zend_reference_destroy()
2025-03-02 22:41:21 +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
2042fd34e0 Support first-class callables in const-expressions (#17213)
RFC: https://wiki.php.net/rfc/fcc_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-02-20 18:52:47 +01:00
Gina Peter Banyard
65d433161a Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Ilija Tovilo
4172b60818 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix segfault when assigning to backing value by-ref from hook
2025-02-05 18:06:41 +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
Tim Düsterhus
5052b325fe zend_execute: Fix misleading UnhandledMatchError messages when exception_string_param_max_len=0 (#17601) 2025-01-31 11:12:19 +01:00
Tim Düsterhus
8c68fe1b5c Merge branch 'PHP-8.4'
* PHP-8.4:
  zend_execute: Suppress values in `UnhandledMatchError` for `zend.exception_ignore_args=1` (#17619)
2025-01-31 10:21:49 +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
Christoph M. Becker
91e6f2621c Add sanitity checks regarding num_args and arg_info (GH-16538)
`num_args > 0` implies that `arg_info != NULL`.  We explicitly assert
that during compilation and execution to make it easier for developers
to not miss this[1].

[1] <https://github.com/php/php-src/issues/16266>
2024-10-25 15:52:53 +02:00
Ilija Tovilo
16d25da76b Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix op2 caching for static properties
  Split expression
2024-10-14 13:46:04 +02:00
Ilija Tovilo
67318e91bc Fix op2 caching for static properties
op2.num may contain other flags, like ZEND_FETCH_CLASS_EXCEPTION. These
currently circumvent caching. Once the property is cached, these flags have no
influence on the result, so it doesn't seem like this was done on purpose.

Closes GH-16380
2024-10-14 13:45:06 +02:00
Ilija Tovilo
60562175ed Split expression 2024-10-14 13:43:48 +02:00
Dmitry Stogov
33b4bdc448 JIT for INIT_STATIC_METHOD_CALL (#16206)
* JIT for INIT_STATIC_METHOD_CALL

* Fixed typo

* Fix missing LOAD

* Separate zend_get_known_class()
2024-10-07 15:28:23 +03:00
Christoph M. Becker
e3bcbb26b6 Merge branch 'PHP-8.4'
* PHP-8.4:
  Declare zend_call_stack_size_error() as ZEND_API
2024-10-03 22:47:26 +02:00