1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Commit Graph

69607 Commits

Author SHA1 Message Date
Dmitry Stogov
002ae9fab5 Update IR
IR commit: d8fbd3b198007f633a255b855cad036758deefb6

Fixes function JIT failures introduced by e792511179
2026-02-26 23:13:30 -05:00
David Carlier
6c45f7a000 ext/pcre: preg_match() fix memory leak with invalid regexes.
close GH-21290
2026-02-24 22:19:27 +00:00
Ilija Tovilo
ec5a1e001d Fix preloaded constant erroneously propagated to file-cached script
Since GH-15021 preloaded constants are propagated to compiled scripts. This is
problematic for file cache, which assumes all referenced zvals are either
persistently allocated or local to the current script. However, preloaded
constants live in shm as immutable, but not persistent.

To solve this, we'd need to duplicate propagated constants in the optimizer when
file cache is used. This is error prone given it needs to happen in many places.
It's debatable whether constant propagation is even correct in this case, as
running the preloaded script on a restart isn't guaranteed to produce the same
result.

Hence, avoid the issue for now by just not relying on preloaded symbols when
file cache is used.

Fixes GH-21052
Closes GH-21281
2026-02-24 17:28:56 +01:00
Dmitry Stogov
e792511179 Update IR (#21288)
IR commit: ef9341183cdd0489a188a87e74f5b02a359df21b
2026-02-24 18:40:53 +03:00
Ilija Tovilo
f07809f495 Tweak stack limit values for gh20840.phpt
Graciously tested by Andy Postnikov (andypost).

See GH-21086
Closes GH-21275
2026-02-24 02:11:19 +01:00
Ilija Tovilo
9a6a841d77 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Tweak stack limit values for gh20583.phpt
2026-02-24 02:11:09 +01:00
Ilija Tovilo
3692a5fa57 Tweak stack limit values for gh20583.phpt
Graciously tested by Andy Postnikov (andypost).

See GH-21086
Closes GH-21274
2026-02-24 02:10:47 +01:00
David Carlier
296fad10fb ext/pcntl: fix pcntl_signal_dispatch() stale tail pointer and exception handling.
close GH-21259
2026-02-23 21:24:38 +00:00
David Carlier
6a1bde5d38 ext/pcntl: Fix signal table updated before php_signal4 succeeds in pcntl_signal
Move the signal table update after the php_signal4 call, mirroring
what is already done in the SIG_DFL/SIG_IGN (integer) code path.
This prevents a stale entry in the table if sigaction fails.

close GH-21270
2026-02-23 12:47:55 +00:00
David Carlier
37ce67f276 ext/pcntl: Fix cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID
Add missing PCNTL_CPU_DESTROY(mask) call before RETURN_THROWS() when
the cpu id is out of range, matching the cleanup on other error paths.

close GH-21268
2026-02-22 19:57:19 +00:00
David Carlier
e2a5909ba3 ext/pcntl: fix pcntl_setns() error handling.
Save errno into a local int before calling close(fd), as close() may
clobber errno on failure. Use int rather than errno_t because errno_t
is defined in C11 Annex K (bounds-checking interfaces) which is
optional and not widely implemented — many platforms (Linux/glibc,
musl, macOS, FreeBSD) do not provide it.

close GH-21256
2026-02-22 19:05:55 +00:00
Niels Dossche
e2059a4697 curl: Don't truncate length
Truncating to an int seems dangerous, esp. in combination with a MIN
macro. I don't see a reason to truncate the length from size_t to int,
and especially no reason to change the signedness.

Closes GH-20747.
2026-02-17 23:15:55 +01:00
ndossche
f6887f04f6 Fix memory leaks in openssl_cms_encrypt() when push fails 2026-02-17 21:39:51 +01:00
ndossche
556ec77951 Fix memory leaks in openssl_pkcs7_encrypt() when push fails 2026-02-17 21:39:51 +01:00
ndossche
ef54becb3e Fix missing error propagation when php_array_to_X509_sk() fails
Execution shouldn't continue if this fails because it can give the wrong
results.
2026-02-17 21:39:51 +01:00
ndossche
01d598aea3 Fix memory leaks in php_array_to_X509_sk() when push fails 2026-02-17 21:39:50 +01:00
ndossche
4b9e80eae9 Fix memory leak in php_openssl_load_all_certs_from_file() when push fails 2026-02-17 21:39:50 +01:00
Ilija Tovilo
1931472f22 Fix borked SCCP of array containing partial object
In SCCP, arrays containing partial objects must be marked as partial so that
their values are not accidentally propagated.

Fixes GH-21227
Closes GH-21232
2026-02-17 18:11:28 +01:00
David Carlier
f7af877cfe ext/pgsql: fix GH-21165 unit test.
making it fails early instead.

close GH-21234
2026-02-17 04:26:42 +00:00
Jordi Kroon
37c5a13d67 replace alloca with do_alloca in mb_guess_encoding_for_strings
This avoids a crash in cases where the list of candidate encodings is so huge
that alloca would fail. Such crashes have been observed when the list of
encodings was larger than around 208,000 entries.
2026-02-17 06:46:42 +09:00
David Carlier
b6495c189a ext/sockets: socket_sendto() add max addr length control for AF_UNIX.
we just mirror what is done for socket_connect()/AF_UNIX type.

close GH-21218
2026-02-15 21:54:19 +00:00
David Carlier
539c5d9f76 Fix GH-21162: pg_connect() on error memory leak.
The PHP_PQ_ERROR macro calls php_error_docref() which triggers user error handlers
thus libpq does not have the chance to clean the resources (and empty
connections string are allowed) on failure thus we avoid this macro
and delay the error handling after.

close GH-21165
2026-02-15 21:26:23 +00:00
Dmitry Stogov
dd9421d825 Update IR (#21183)
IR commit: a098f9ed6c2f1c2852d6c0921283212aafb4afed
2026-02-10 01:34:09 +03:00
David Carlier
19ee3e6697 Fix GH-21161: socket_set_option() crash with array 'addr' entry as null.
in the ipv6 address creation helper we need to use, for the error
message, the converted data rather than assuming the original
is a proper zend_string().

close GH-21166
2026-02-09 19:26:48 +00:00
Petr Sumbera
7c6f08945f Improve shared_alloc_shm.c strategy to support OPcache JIT on Solaris
The SysV shared memory allocator in OPcache hardcodes a maximum segment size of
32MB (SEG_ALLOC_SIZE_MAX). If the JIT buffer exceeds this, which it does with
the default 64MB size, startup will fail with "Insufficient shared memory!".

The allocator will now try allocating a contiguous buffer first, and only then
use segmentation by searching for continuously smaller powers of 2.

Fixes GH-20718
Closes GH-20719
2026-02-09 14:58:13 +01:00
Ilija Tovilo
bbde9c8178 Fix OSS-Fuzz #478009707 for JIT
This issue was already fixed in GH-21124, but some JIT paths were missing.

Closes GH-21151
2026-02-08 16:46:08 +01:00
Niels Dossche
ee26417b58 Fix timezone offset with seconds losing precision
There are two issues:
1. The 'e' formatter doesn't output the seconds of the timezone even if
   it has seconds.
2. var_dump(), (array) cast, serialization, ... don't include the
   timezone second offset in the output. This means that, for example,
   serializing and then unserializing a date object loses the seconds of
   the timezone. This can be observed by comparing the output of
   getTimezone() for `$dt` vs the unserialized object in the provided test.

Closes GH-20764.
2026-02-05 18:38:54 +01:00
Niels Dossche
7445b0f6d9 Fix GH-20936: DatePeriod::__set_state() cannot handle null start
The "current" and "end" field also rely on start_ce, which is set by
"start". Therefore, if "current" or "end" are provided, so must "start"
be provided.

Closes GH-20939.
2026-02-04 18:34:38 +01:00
Niels Dossche
b8fc6bd1c8 Fix GH-21097: Accessing Dom\Node properties can can throw TypeError(s)
Split the handler again, or defer to instanceof when performance doesn't
matter.

Closes GH-21108.
2026-02-03 18:36:28 +01:00
Ilija Tovilo
1f57d04648 Tweak zend.max_allowed_stack_size for gh20836_stack_limit.phpt
Fixes GH-21086
2026-02-03 00:54:25 +01:00
Niels Dossche
d73b2f782e Fix GH-21077: Accessing Dom\Node::baseURI can throw TypeError
Prior to this patch there was a common read handler, and it relied on
the dom class set in the intern document. However, Dom\Implementation
allows creating DTDs unassociated with a document, so we can't rely on
an intern document and the check fails. This causes the ZVAL_NULL() path
to be taken.
To solve this, just split the handler.

Closes GH-21082.
2026-01-30 18:13:55 +01:00
David Carlier
b156471a30 Fix GH-21023: CURLOPT_XFERINFOFUNCTION with invalid callback crash.
we check the FCC is properly initialised beforehand in its handler.

close GH-21025
2026-01-30 13:09:44 +00:00
Loïc Saos
3037526810 Fix GH-21055: Pdo/Pgsql typo for GSS negotiation connection status attribute.
close GH-21057
2026-01-28 18:12:08 +00:00
Alexander Borisov
56e5a80c44 Fix GH-21041: Dom\HTMLDocument corrupts closing tags within scripts 2026-01-26 19:20:10 +01:00
Michael Orlitzky
3053a039ff ext/dba/tests/dba_db4_018.phpt: fix typo (#20938)
We expect "objects" but print "object".

Gentoo-bug: https://bugs.gentoo.org/968656
2026-01-24 11:38:45 +00:00
Niels Dossche
62afc7a2fa Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails
The X509_NAME_oneline() function can return NULL, which will cause a
crash when the string length is computed via add_assoc_string().

Closes GH-21010.
2026-01-23 14:59:08 +01:00
Niels Dossche
c2eadb4922 Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails
The X509_NAME_oneline() function can return NULL,
which will cause a crash when the string length is computed via add_assoc_string().

Closes GH-21011.
2026-01-23 14:58:39 +01:00
Niels Dossche
7754eafb1f Fix memory leaks when sk_X509_new_null() fails
In a lot of places the return value is not checked, and when the
function fails the code continues execution. However, this means that
operations on the stack fail and will cause memory leaks on the objects
that weren't pushed.

We also notice an inconsistency in how these failures are handled.
For example, in one place we explicitly have a fatal error
`php_error_docref(NULL, E_ERROR, "Memory allocation failure");`
but this is the only place to do so.

Closes GH-20957.
2026-01-22 22:37:14 +01:00
Ilija Tovilo
4367315183 [skip ci] Reduce zend.max_allowed_stack_size in gh20840.phpt
This test still fails on i386 Windows with "Allowed memory size of %d bytes
exhausted" because the output buffer grows too big. My first intuition was to
add a chunk_size to ob_start, but this won't work if the output buffer is
flushed deep into the call stack, causing a premature or just a second stack
limit error. So, reduce the stack size in an attempt to produce less output.
2026-01-21 17:32:01 +01:00
Chris Hasiński
1db1c7f5c1 Fix segfault in Tracing JIT with object reference (GH-20818)
When FE_RESET_RW executes, it converts the CV to a reference before
checking if the array/object is empty. However, when the JIT creates
exit points for FE_RESET_RW in zend_jit_trace_handler(), it wasn't
updating the stack type for op1 to reflect this change.

This caused side traces compiled from these exit points to have
incorrect type information. The side trace's CV cleanup code would
see IS_OBJECT and generate a direct call to zend_objects_store_del(),
but the actual value was a zend_reference*, causing a segfault.

The fix adds ZEND_FE_RESET_RW to the list of opcodes that temporarily
set their op1 stack type to IS_UNKNOWN before creating exit points.
This follows the same pattern used for ZEND_BIND_INIT_STATIC_OR_JMP.
When IS_UNKNOWN, the JIT falls back to SSA type info which correctly
includes MAY_BE_REF for FE_RESET_RW's op1_def.

Fixes GH-20818
Closes GH-20948
2026-01-21 00:24:14 +01:00
Niels Dossche
32c0245531 Revert "Fix GH-20890: Segfault in zval_undefined_cv with non-simple property hook with minimal tracing JIT"
This reverts commit 57c62eb2b3.
2026-01-20 21:05:26 +01:00
Niels Dossche
57c62eb2b3 Fix GH-20890: Segfault in zval_undefined_cv with non-simple property hook with minimal tracing JIT
This is similar to f6c2e40a11 but for minimal JIT + tracing JIT.
Most of the times the tracing JIT shouldn't rely on going to the VM, but
in some cases, like in minimal JIT, it can and then it hits the same
bug.

Closes GH-20897.
2026-01-20 18:55:08 +01:00
David Carlier
5785ff7728 exp/pgsql: insert/update query string build possible UB fix.
From PQescapeIdentifier() docs

```
A terminating zero byte is not required, and should not be counted in
length
```
2026-01-19 06:17:23 +00:00
Peter Kokot
c4084bb8f3 Use PHP 8+ square brackets for array elements
The curly braces syntax for array elements has been removed in PHP 8.0.
2026-01-18 17:58:00 +01:00
Ilija Tovilo
462fcad419 Avoid huge output in gh20840.phpt
This can trigger the memory limit in run-tests.php, which buffers the tests
output. Instead, only output "nesting level too deep" and discard the rest.

Closes GH-20946
2026-01-16 13:03:53 +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
Alexandre Daubois
2c112e3696 Fix GH-20836: Stack overflow in mb_convert_variables with recursive array references (#20839) 2026-01-14 20:07:11 +01:00
Derick Rethans
c929f2aa87 Update generated parser file 2026-01-14 14:21:29 +00:00
Derick Rethans
ba1f3d9a87 Revert "Updated to version 2025.3 (2025c)"
This reverts commit 2670c8646d.
2026-01-14 14:16:47 +00:00
Derick Rethans
cfbfc1b6f6 Revert "Upgrade timelib to 2022.16"
This reverts commit e208cd86b4.
2026-01-14 14:16:40 +00:00