Commit graph

66183 commits

Author SHA1 Message Date
Niels Dossche
fdeadcd9ba
Fix branch target in zend_jit_push_call_frame()
Introduced by accident in 3b4a58da44.
Will request a cherry-pick.
2025-03-12 06:10:27 -07:00
Niels Dossche
ebf5902292
Fix GHSA-wg4p-4hqh-c3g9 2025-03-05 20:42:10 +01:00
Tim Düsterhus
054ea51d1d
Fix GHSA-p3x9-6h7p-cgfc: libxml streams wrong content-type on redirect
libxml streams use wrong content-type header when requesting a
redirected resource.
2025-03-05 14:12:59 +01:00
Jakub Zelenka
fac131fa95
Fix GHSA-hgf5-96fm-v528: http user header check of crlf 2025-03-05 13:42:47 +01:00
Jakub Zelenka
ae14a0b9fe
Fix GHSA-52jp-hrpf-2jff: http redirect location truncation
It converts the allocation of location to be on heap instead of stack
and errors if the location length is greater than 8086 bytes.
2025-03-05 13:42:03 +01:00
Jakub Zelenka
455161cdae
Fix GHSA-pcmh-g36c-qc44: http headers without colon
The header line must contain colon otherwise it is invalid and it needs
to fail.

Reviewed-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-03-05 13:41:18 +01:00
Jakub Zelenka
bf30a4454d
Fix GHSA-ghsa-v8xr-gpvj-cx9g: http header folding
This adds HTTP header folding support for HTTP wrapper response
headers.

Reviewed-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-03-05 12:11:19 +01:00
Jakub Zelenka
930624899b
Fix bug #72666: stat cache not cleared for plain paths
This adds more aggressive clearing of stat cache. It is added to the
filestat as well as plain wrapper operations which covers stream file
accessing as well as exec functions (using pipes). It should hopefully
fix the most visible issues with the stat cache.

Closes GH-17681
2025-02-24 23:21:45 +01:00
Niels Dossche
3b4a58da44
Backport GH-17869 to PHP 8.3 JIT
Closes GH-17918.
2025-02-24 21:45:03 +01:00
Michael Orlitzky
174a7fe6f9
Fix GH-17891 gh17373.phpt test issue without freetype support
skip if imagefttext() is not available

This test calls imagefttext(), which may not be available if libgd
was built without freetype support.

Closes GH-17910
2025-02-24 07:13:11 +00:00
Michael Orlitzky
065b4ec125
ext/gd/tests: backport optional PNG support
- Three of our gd tests could be skipped with a message about requiring
bundled GD, but those tests don't actually require bundled GD. We
update the messages to mention the specific functions that are
required.

- add SKIPIF stanzas for missing PNG support

The bundled libgd always has PNG support, but an external one may not.

- imagerotate() is always available

Following 59ec80c5, the imagerotate() function is always available. We
may therefore remove its function_exists() checks without harm.

close GH-17894
2025-02-23 16:01:30 +00:00
Niels Dossche
353f21487f
Fix cycle leak in sqlite3 setAuthorizer()
Closes GH-17903.
2025-02-23 16:34:41 +01:00
David Carlier
2c251f945c
[skip ci] zend_test adding closing tags to newer tests 2025-02-23 13:23:26 +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
Christoph M. Becker
769f292a7a
Fix GH-17879: readfile_variation8-win32.phpt test conflict
Apparently a copy and paste issue.

Closes GH-17881.
2025-02-22 00:09:53 +01:00
Niels Dossche
9becccef17
Fix GH-17847: xinclude destroys live node
dom_xinclude_strip_fallback_references() now also takes into account
xi:include nodes children. This now subsumes all work done normally by
the old start/end node removal, so we can remove that code and start
using XML_PARSE_NOXINCNODE.

Closes GH-17878.
2025-02-21 22:24:44 +01:00
Christoph M. Becker
200f16fcf7
Fix GH-17855: CURL_STATICLIB flag set even if linked with shared lib
We must define `CURL_STATICLIB` only when building against a static
libcurl.  The detection relies on our usual naming conventions, what
should be revised in the future (possibly using pkg-config, or
switching to CMake).

Closes GH-17857.
2025-02-21 13:08:01 +01:00
Daniel Scherzer
ca0414e64d
Reflection: show the type of object constants used as default properties
When a property default is based on a global constant, show the type of the
default. Previously, `format_default_value()` assumed that non-scalar and
non-array defaults were always going to be `IS_CONSTANT_AST` pointers, and when
the AST expression had been evaluated and produced an object, depending on when
the `ReflectionClass` or `ReflectionProperty` instance had been created, the
default was shown as one of `callable` or `__CLASS__`.

Instead, if the default value is an object (`IS_OBJECT`), show the type of that
object.

Add test cases for both of the `callable` and `__CLASS__` cases to confirm that
they now properly show the type of the constant.

Closes GH-15902.
Closes GH-17781.
2025-02-21 09:32:10 +01:00
Christoph M. Becker
260e0e9bd3
Fix GH-17837: ::getColumnMeta() on unexecuted statement segfaults
We cannot properly get the column meta data of a statement which has
been prepared, but has not yet been executed.  As such we bail out
early, reporting failure.

Closes GH-17850.
2025-02-18 17:01:46 +01:00
David Zhong
52c91f0fb7
Fix FFI Parsing of Pointer Declaration Lists (#17794)
* Fix ffi parsing of pointer declaration lists

* Fix ffi pointer declaration lists grammar
2025-02-17 10:27:11 +03:00
Christoph M. Becker
765cebf73a
Adapt tests to Windows 11
Apparently, one of the more recent patch releases of Windows 10
(confirmed for Windows 10.0.26100, but may affect older versions, too)
changed treatment of filenames with trailing slashes to be recognized
explicitly as directories, and no longer as invalid file or directory.

We adapt the affected test cases.

Closes GH-17804.
2025-02-17 00:07:55 +01:00
Niels Dossche
3e879f3dd5
[ci skip] Fix GH-17808 dependencies 2025-02-16 00:16:57 +01:00
Niels Dossche
e735d2bc3b
Fix GH-17808: PharFileInfo refcount bug
PharFileInfo just takes a pointer from the manifest without refcounting
anything. If the entry is then removed from the manifest while the
PharFileInfo object still exists, we get a UAF.
We fix this by using the fp_refcount field. This is technically a
behaviour change as the unlinking is now blocked, and potentially file
modifications can be blocked as well. The alternative would be to have a
field that indicates whether deletion is blocked, but similar corruption
bugs may occur as well with file overwrites, so we increment fp_refcount
instead.
This also fixes an issue where a destructor called multiple times
resulted in a UAF as well, by moving the NULL'ing of the entry field out
of the if.

Closes GH-17811.
2025-02-15 13:15:51 +01: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
5aaf7b4937
Fix zlib support for large files
gzread() and gzwrite() have effectively a 4GiB limit at the moment
because the APIs of the zlib library use unsigned ints.
For example, this means that the count argument of gzread() and gzwrite()
& co effectively are modulo 2**32.
Fix this by adding a loop to handle all bytes.

As for automated testing, I didn't find an easy way to write a phpt for
this that wouldn't use a lot of memory or requires a large file.
For instance, the gzread() test that I manually ran requires a 4MiB
input file (and I can't shrink it because zlib has a max window size).

Here are the testing instructions, run on 64-bit:
To test for gzwrite():
```php
$f = gzopen("out.txt.gz", "w");
gzwrite($f, str_repeat('a', 4*1024*1024*1024+64)); // 4GiB + 64 bytes
```
Then use `zcat out.txt.gz|wc -c` to check that all bytes were written
(should be 4294967360).

To test for gzread():
Create a file containing all a's for example that is 4GiB + 64 bytes.
Then compress it into out.txt.gz using the gzip command.
Then run:
```php
$f = gzopen("out.txt.gz", "r");
$str = gzread($f, 4*1024*1024*1024+64);
var_dump(strlen($str)); // 4294967360
var_dump(substr($str, -3)); // string (3) "aaa"
```

Closes GH-17775.
2025-02-14 23:09:57 +01:00
David Carlier
4d7d01d18e
Fix GH-17772: imagepalettetotruecolor segfault on invalid truecolor pixel.
close GH-17777
2025-02-14 15:28:33 +00:00
ndossche
a54af45a41
Fix memory leak when encoding check fails
zlib_create_dictionary_string() allocates memory, so we can leak memory
if there's an early exit before the assignment to the return value.
Solve this by moving all validation upwards.

Closes GH-17788.
2025-02-13 19:10:17 +01:00
Niels Dossche
4b5c29ef50
Fix GH-17745: zlib extension incorrectly handles object arguments
Because of the "H" modifier in ZPP, there are two bugs:

1) The stub is wrong and will cause a crash in debug mode.
2) Non-dynamic properties are not read correctly because they are not
   DEINDIRECTed.

Closes GH-17750.
2025-02-11 21:52:53 +01:00
Niels Dossche
fd5d6ad5bd
Fix GH-17650: realloc with size 0 in user_filters.c
If the returned buffer string is of length 0, then a realloc can happen
with length 0. However, the behaviour is implementation-defined.
From 7.20.3.1 of C11 spec:

> If the size of the space requested is zero, the behavior is
> implementation-defined: either a null pointer is returned,
> or the behavior is as if the size were some nonzero value,
> except that the returned pointer shall not be used to access an object

This is problematic for the test case on my system as it returns NULL,
causing a memleak and later using it in memcpy causing UB.
The bucket code is not prepared to handle a NULL pointer.
To solve this, we use MAX to clamp the size to 1 at the least.

Closes GH-17656.
2025-02-07 20:22:52 +01:00
Niels Dossche
2fb88b2d80
Fix GH-17704: ldap_search fails when $attributes contains a non-packed array with numerical keys
Closes GH-17710.
2025-02-06 23:31:01 +01:00
Ilija Tovilo
68d2bc42fc
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add CONFLICT all to random port test
2025-02-06 15:25:47 +01:00
Ilija Tovilo
c5045a04f2
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Add CONFLICT all to random port test
2025-02-06 15:25:41 +01:00
Ilija Tovilo
726cf51236
Add CONFLICT all to random port test
If we're very unlucky, we can get the same port opened as an ephemeral
port by some other test.

Closes GH-17706
2025-02-06 15:25:16 +01:00
Christoph M. Becker
47931a426e
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix curl_basic_022.phpt for libcurl 8.12.0
2025-02-05 19:22:51 +01:00
Christoph M. Becker
856866ef24
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix curl_basic_022.phpt for libcurl 8.12.0
2025-02-05 19:22:20 +01:00
Christoph M. Becker
36d46a4732
Fix curl_basic_022.phpt for libcurl 8.12.0
Due to a deliberate change in libcurl, the expiration is now capped to
at most 400 days.  We could solve this by choosing another date roughly
a year in the future, but would need to update the test next year.
This would be especially annoying for security branches.

Another option would be to actually parse the cookie list lines, but
that might not be worth the trouble.  Instead we just ignore the exact
timestamp created by libcurl.

[1] <https://github.com/curl/curl/pull/15937>

Closes GH-17709.
2025-02-05 19:20:47 +01:00
Christoph M. Becker
55e676e181
Fix GH-17503: Undefined float conversion in mb_convert_variables
Conversion of floating point to integer values is undefined if the
integral part of the float value cannot be represented by the integer
type.  We need to cater to that explicitly (in a manner similar to
`zend_dval_to_lval_cap()`).

Closes GH-17689.
2025-02-04 15:51:48 +01:00
Ilija Tovilo
88e1917cb7
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Another flaky phar macOS test
2025-02-04 14:52:23 +01:00
Ilija Tovilo
99d2055670
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Another flaky phar macOS test
2025-02-04 14:52:15 +01:00
Ilija Tovilo
d8aedb589c
[skip ci] Another flaky phar macOS test 2025-02-04 14:52:03 +01:00
Niels Dossche
0c3cf1f311
Fix GH-17577: JIT packed type guard crash
When a guard check is created for a variable to check if it's a packed array,
it is possible that there was no prior type check for that variable.
This happens in the global scope for example when the variable aliases.
In the test, this causes a dereference of address 8 because the integer
element in `$a` is interpreted as an array address.

This patch adds a check to see if the guard is handled.
If we were not able to determine or guard the type then we also cannot know the array is packed.

Closes GH-17584.
2025-02-03 19:34:39 +01:00
Niels Dossche
f88445bdf8
Fix GH-17654: Multiple classes using same trait causes function JIT crash
This test has two classes that use the same trait. In function JIT mode
the same cache slot will be used. This causes problems because it is
primed for the first class and then reused for the second class,
resulting in an incorrect type check failure.

The current check for a megamorphic trait call requires current_frame to
not be NULL, but this is only set in tracing mode and not in function
mode.

This patch corrects the check.

Closes GH-17660.
2025-02-03 19:21:15 +01:00
Christoph M. Becker
76fccc2b02
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Relax timezone_IDforWindowsID_basic2.phpt expectations
2025-02-02 13:37:21 +01:00
Christoph M. Becker
036f00f146
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Relax timezone_IDforWindowsID_basic2.phpt expectations
2025-02-02 13:36:39 +01:00
Christoph M. Becker
afe8e2cdff
Relax timezone_IDforWindowsID_basic2.phpt expectations
Apparently, some ICU versions report "America/Los_Angeles" for the `ZZ`
case, what matches the behavior of ICU 76.1 (on Windows).  Possibly,
there has been some bug fix backport on some systems.  Anyhow, either
seems fine, so we're not picky about that.

Closes GH-17669.
2025-02-02 13:35:27 +01:00
Saki Takamachi
5a4832f97b
Fixed GH-17398: bcmul memory leak (#17615)
Changed BCG memory allocation to be forcibly released in
PHP_GSHUTDOWN_FUNCTION regardless of refcount.

Fixes #17398
Closes #17615
2025-01-29 19:12:18 +09:00
Remi Collet
ed1d51fa4f
relax test for zlib-ng 2025-01-29 11:03:59 +01:00
Ilija Tovilo
dc06a52362
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Another flaky macOS phar test
2025-01-28 12:58:55 +01:00
Ilija Tovilo
c14601cc90
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Another flaky macOS phar test
2025-01-28 12:58:42 +01:00
Ilija Tovilo
d9744869e6
[skip ci] Another flaky macOS phar test 2025-01-28 12:58:30 +01:00