Commit graph

497 commits

Author SHA1 Message Date
Gina Peter Banyard
1c67b060c4 main: Add bailout tests for dir opening on user stream 2025-08-15 18:41:17 +02:00
Tim Düsterhus
922c225fbf
reflection: Deprecate Reflection*::setAccessible() (#19273)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_reflectionsetaccessible
2025-08-08 21:24:41 +01:00
Arnaud Le Blanc
32290b3529
Add opcache_preloading() internal function
Add a C function, opcache_preloading(), that returns true during
preloading. Extensions can use this to detect preloading, not only during
compilation/execution, but also in RINIT()/RSHUTDOWN().

Since opcache currently doesn't install any header, I'm adding a new one:
zend_accelerator_api.h. Header name is based on other files in ext/opcache.

Closes GH-19288
2025-08-06 18:21:19 +02:00
Gina Peter Banyard
fc6c49cbf4 ext/zend_test: Test zend_call_method_if_exists() 2025-07-30 12:02:41 +01:00
Daniel Scherzer
ff810d5e36
Arginfo: reuse zend_string objects for initializing attribute values (#19241)
Avoid initializing the same string content multiple times and make use of the
fact that the strings created to initialize attribute values are not freed by
simply making use of an existing zend_string with the same content if one is
available.
2025-07-27 17:27:22 -07:00
DanielEScherzer
1eadf553f1
Arginfo: avoid using temporary zvals for initializing attribute values (#19141)
Instead of
* adding a zval on the stack
* initializing it
* copying the value to the attribute

Just initialize the value directly in the zend_attribute_arg
2025-07-21 13:33:51 -07:00
Niels Dossche
502c68264d
Merge branch 'PHP-8.4'
* PHP-8.4:
  pdo_odbc: Fix memory leak if WideCharToMultiByte() fails
  Fix memory leak on php_odbc_fetch_hash() failure
  Do not delete main chunk in zend_gc
2025-06-09 11:26:27 +02:00
Niels Dossche
5526301908
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  pdo_odbc: Fix memory leak if WideCharToMultiByte() fails
  Fix memory leak on php_odbc_fetch_hash() failure
  Do not delete main chunk in zend_gc
2025-06-09 11:25:41 +02:00
Daniil Gentili
9a9d98e02f
Do not delete main chunk in zend_gc
Closes GH-18756.

Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2025-06-09 11:23:29 +02:00
DanielEScherzer
8f3cdf6236
gen_stub: Add support for attributes on constants in stubs (#18735)
Update to PHP-Parser 5.5.0 and add support for attributes on constants in
stubs. For now, I have only migrated over E_STRICT, once the support is in
place I'll do a larger migration of the existing deprecated constants.

In the process, fix the logic in `copy_zend_constant()` for copying attributes
when a constant is copied; just increase the reference count for the attributes
table rather than trying to duplicate the contents.
2025-06-05 14:46:46 -07:00
Gina Peter Banyard
ea2656277b
Fix INI setting requirements for test with opcache
Closes GH-18551
2025-05-22 14:18:41 +01:00
Tim Düsterhus
73c4e9f0b2
Merge branch 'PHP-8.4'
* PHP-8.4:
  gen_stub: Fix `ce_flags` generation for compatibility mode (#18507)
2025-05-09 13:33:58 +02:00
Tim Düsterhus
84f82d0a1c
gen_stub: Fix ce_flags generation for compatibility mode (#18507)
* gen_stub: Fix `ce_flags` generation for compatibility mode

Fixes php/php-src#18506

* gen_stub: Improve output for ce_flags compatibility
2025-05-09 13:33:09 +02:00
DanielEScherzer
940ee1a641
gen_stub: ZEND_ACC_NODISCARD is for PHP 8.5+ (#18465) 2025-05-04 15:08:37 -07: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
Tim Düsterhus
f14697416e
ext/standard: Remove #[\NoDiscard] from flock() (#18255)
Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-08 14:23:03 +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
Arnaud Le Blanc
cb245411b0
Add runtime-enabled heap debugging capabilities (#18172)
Debugging memory corruption issues in production can be difficult when it's not possible to use a debug build or ASAN/MSAN/Valgrind (e.g. for performance reasons).

This change makes it possible to enable some basic heap debugging helpers without rebuilding PHP. This is controlled by the environment variable ZEND_MM_DEBUG. The env var takes a comma-separated list of parameters:

- poison_free=byte: Override freed blocks with the specified byte value (represented as a number)
- poison_alloc=byte: Override newly allocated blocks with the specified byte value (represented as a number)
- padding=bytes: Pad allocated blocks with the specified amount of bytes (if non-zero, a value >= 16 is recommended to not break alignments) 
- check_freelists_on_shutdown=0|1: Enable checking freelist consistency [1] on shutdown

Example:

    ZEND_MM_DEBUG=poison_free=0xbe,poison_alloc=0xeb,padding=16,check_freelists_on_shutdown=1 php ...

This is implemented by installing custom handlers when ZEND_MM_DEBUG is set.

This has zero overhead when ZEND_MM_DEBUG is not set. When ZEND_MM_DEBUG is set, the overhead is about 8.5% on the Symfony Demo benchmark.

Goals:

 - Crash earlier after a memory corruption, to extract a useful backtrace
 - Be usable in production with reasonable overhead
 - Having zero overhead when not enabled

Non-goals:

 - Replace debug builds, valgrind, ASAN, MSAN or other sanitizers

[1] https://github.com/php/php-src/pull/14054

Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
2025-03-31 17:24:42 +02:00
Niels Dossche
0097ad8eb3
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 (#17958)
2025-03-03 08:22:55 +01:00
Niels Dossche
4c751ec04c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 (#17958)
2025-03-03 08:22:49 +01:00
Niels Dossche
504056888c
Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 (#17958) 2025-03-03 08:20:48 +01:00
David Carlier
388134769b
Merge branch 'PHP-8.4' 2025-02-23 13:23:48 +00:00
David Carlier
96340e9eed
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 13:23:38 +00:00
David Carlier
2c251f945c
[skip ci] zend_test adding closing tags to newer tests 2025-02-23 13:23:26 +00:00
David Carlier
f89b0a229c
Merge branch 'PHP-8.4' 2025-02-23 10:45:55 +00:00
David Carlier
e8dda54dd5
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 10:45:46 +00:00
David Carlier
cefdf00e7e
Fix GH-17899: zend_test_compile_string crash on invalid script path.
when opcache is enabled.

close GH-17901
2025-02-23 10:45:10 +00:00
David CARLIER
3b82367871
Fix GH-17831: zend_test_compile_string crash on nul bytes check. (#17832)
Setting check_null previously was due to misunderstanding its purpose
2025-02-16 11:14:19 +00:00
David CARLIER
d3da2a2884
zend_test: zend_test_compile_string converting script argument to path. (#17810) 2025-02-15 11:15:08 +00:00
David Carlier
01a87e0d2d
Merge branch 'PHP-8.4' 2025-02-15 10:12:34 +00:00
David Carlier
eabbb1c1c6
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-15 10:12:20 +00:00
David Carlier
0f63bee3e9
Fix GH-17797: zend_test_compile_string crash on invalid script path.
When looking for the last slash of the script path, it leads to
underflow being promoted to SIZE_MAX being way beyond MAXPATHLEN.

close GH-17801
2025-02-15 10:11:27 +00:00
Niels Dossche
3786b721e8
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17408: Assertion failure Zend/zend_exceptions.c
2025-01-21 08:21:27 +01:00
Niels Dossche
25543b4566
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17408: Assertion failure Zend/zend_exceptions.c
2025-01-21 08:21:13 +01:00
Niels Dossche
5344bcca97
Fix GH-17408: Assertion failure Zend/zend_exceptions.c
`zend_test_create_throwing_resource` sets the exception in the `test`
call frame and unwinds to `main`. It then throws for the `resource`
variable and verifies that the exception opline is set. However, it
wasn't set in `main`, it was set at the `test` call frame and rethrown later.
The assertion is too conservative, but the end result is right, so drop
the assertion.

Closes GH-17533.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-01-21 08:20:38 +01:00
Máté Kocsis
684ef016e1
Add support for using final properties in stubs (#17306) 2025-01-06 07:56:13 +01:00
Niels Dossche
1331444822
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16013 and bug #80857: Big endian issues
2024-12-25 21:33:49 +01:00
Niels Dossche
250e0ffe90
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16013 and bug #80857: Big endian issues
2024-12-25 21:33:43 +01:00
Niels Dossche
99a14b805e
Fix GH-16013 and bug #80857: Big endian issues
The FFI call return values follow widening rules.
We must widen to `ffi_arg` in the case we're handling a return value for types shorter than the machine width.
From http://www.chiark.greenend.org.uk/doc/libffi-dev/html/The-Closure-API.html:
> In most cases, ret points to an object of exactly the size of the type specified when cif was constructed.
> However, integral types narrower than the system register size are widened.
> In these cases your program may assume that ret points to an ffi_arg object.

If we don't do this, we get wrong values when reading the return values.

Closes GH-17255.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2024-12-25 21:33:14 +01:00
Niels Dossche
4c189ae585
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix test expectation for PHP 8.3+
2024-11-25 20:33:26 +01:00
Niels Dossche
ec9a606e5d
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix test expectation for PHP 8.3+
2024-11-25 20:33:20 +01:00
Niels Dossche
ff95138e38
Fix test expectation for PHP 8.3+ 2024-11-25 20:33:14 +01:00
Niels Dossche
5e9273ad0a
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2024-11-25 19:39:06 +01:00
Niels Dossche
43a3bd0608
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2024-11-25 19:39:01 +01:00
Niels Dossche
d9fada4a71
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2024-11-25 19:38:50 +01:00
Niels Dossche
99f5653ebb
Fix GH-16908: _ZendTestMagicCallForward does not handle references well
This testing code was never meant to be used this way, but fixing this
will at least stop fuzzers from complaining about this, so might still
be worthwhile.

Closes GH-16919.
2024-11-25 19:38:33 +01:00
Ilija Tovilo
06b99c059e
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix compiler warning in zend_test
2024-11-05 16:52:00 +01:00
Arnaud Le Blanc
8d30ed4f80
Fix compiler warning in zend_test
Closes GH-16650
2024-11-05 16:51:43 +01:00
Niels Dossche
64f2d11e38
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:39:00 +01:00
Niels Dossche
bfd9e0cca3
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:38:54 +01:00