1
0
mirror of https://github.com/php/php-src.git synced 2026-04-18 05:21:02 +02:00
Commit Graph

2663 Commits

Author SHA1 Message Date
George Peter Banyard
fcba0a49fc Fix test file name to not include a whitespace
This breaks the preload file flag in the test runner
2022-05-31 11:28:01 +01:00
George Peter Banyard
fc799ecdbe Move SplFileObject tests into subfolder 2022-05-27 18:33:48 +01:00
Christoph M. Becker
e5d9859b50 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:59 +02:00
Christoph M. Becker
e004e1a93b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:39 +02:00
Christoph M. Becker
ad7b9f4e50 Fix GH-8235: iterator_count() may run indefinitely
We need to prevent integer overflow to eventually stop the iteration.

A test case doesn't appear sensible for this, because even on 32bit
architectures a respective test easily runs for a few minutes.

Closes GH-8447.
2022-05-03 12:57:58 +02:00
George Peter Banyard
cf51d8ffe7 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8273: SplFileObject: key() returns wrong value
2022-04-23 14:02:01 +01:00
George Peter Banyard
660ef91fbc Fix GH-8273: SplFileObject: key() returns wrong value 2022-04-23 14:00:11 +01:00
George Peter Banyard
6186ecd436 Fix GH-8273: SplFileObject: key() returns wrong value 2022-04-23 13:56:38 +01:00
Marco Pivetta
25cb9cdb79 Fix GH-8232 - always reference classes in var_export() via their FQCN
Closes GH-8233

This fix corrects a behavior of `var_export()` that was mostly "hidden" until PHP 8.1 introduced:

* properties with object initializers
* constants containing object references
* default values of class properties containing `enum`s

Since `var_export(..., true)` is mostly used in conjunction with code generation,
and we cannot make assumptions about the generated code being placed in the root
namespace, we must always provide the FQCN of a class in exported code.

For example:

```php
<?php

namespace MyNamespace { class Foo {} }

namespace { echo "<?php\n\nnamespace Example;\n\n" . var_export(new \MyNamespace\Foo(), true) . ';'; }
```

produces:

```php
<?php

namespace Example;

MyNamespace\Foo::__set_state(array(
));
```

This code snippet is invalid, because `Example\MyNamespace\Foo::__set_state()` (which
does not exist) is called.

With this patch applied, the code looks like following (valid):

```php
<?php

namespace Example;

\MyNamespace\Foo::__set_state(array(
));
```

Ref: https://github.com/php/php-src/issues/8232
Ref: https://github.com/Ocramius/ProxyManager/issues/754
Ref: https://externals.io/message/117466
2022-04-23 11:06:21 +02:00
Christoph M. Becker
3de0ccfe09 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8366: ArrayIterator may leak when calling __construct()
2022-04-15 19:10:29 +02:00
Christoph M. Becker
549cf3a24d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8366: ArrayIterator may leak when calling __construct()
2022-04-15 19:08:28 +02:00
Christoph M. Becker
1762a87932 Fix GH-8366: ArrayIterator may leak when calling __construct()
When we detach an iterator, we also have to delete it.

Closes GH-8374.
2022-04-15 19:05:18 +02:00
George Peter Banyard
cfc38a6014 SPL: minor refactoring (#8341)
Use more appropriate types and return macros
2022-04-13 20:34:23 +01:00
George Peter Banyard
7710f9946b Fix generation of arginfo if type is just null 2022-04-11 16:58:13 +01:00
George Peter Banyard
8dbfb15f7c Use more specific return types in SPL 2022-04-11 14:04:37 +01:00
George Peter Banyard
2ac5948f5c Refactor SplFileObject CSV methods (#8317)
Use early returns, which fixes ValueError order of arguments and flattens the code
2022-04-08 20:16:26 +01:00
George Peter Banyard
3931d726c4 Add missing ZPP checks in SPL Directory (#8325)
Co-authored-by: Máté Kocsis <kocsismate@woohoolabs.com>
2022-04-08 17:58:10 +01:00
Arnaud Le Blanc
72fb511d0c Stop including php_pcre.h from spl_iterators.h
This fixes GH-7774.

spl_iterators.h was including php_pcre.h so that one object intern struct could
reference a pcre_cache_entry. These object interns should not be public, so they
can be moved out of the header file.

This change moves the object interns ouf of spl_iterators.h so that php_pcre.h
doesn't need to be included from there.
2022-04-08 10:37:12 +02:00
George Peter Banyard
892270608c Minor refactoring of spl_directory.c
Using more appropriate types
Fix comments
Early returns
2022-04-07 15:12:40 +01:00
Max Kellermann
b9e895bca0 Replace memcmp() with zend_string functions (#8216)
* ext/oci8: use zend_string_equals()

Eliminate duplicate code.

* main/php_variables: use zend_string_equals_literal()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_equals_cstr()

Allows eliminating duplicate code.

* Zend, ext/{opcache,standard}, main/output: use zend_string_equals_cstr()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_starts_with()

* ext/{opcache,phar,spl,standard}: use zend_string_starts_with()

This adds missing length checks to several callers, e.g. in
cache_script_in_shared_memory().  This is important when the
zend_string is shorter than the string parameter, when memcmp()
happens to check backwards; this can result in an out-of-bounds memory
access.
2022-03-31 16:27:58 +02:00
Zhou Qingyang
48e0707620 spl_ptr_llist_offset() is not supposed to return NULL here
This issue has found by a static analyzer.

Closes GH-8272.
2022-03-30 11:38:25 +02:00
George Peter Banyard
db0db2204f Use zend_result/bool in spl_array.c 2022-03-23 22:21:04 +00:00
George Peter Banyard
2fa33d1def Use ZEND_THROWS() where applicable in spl_array.c 2022-03-23 22:13:08 +00:00
George Peter Banyard
69ea2d8600 Convert check + exception to assertion
Move the inside the __unserialize() method as that's the only one which now needs this check

Closes GH-8207
2022-03-23 22:02:27 +00:00
Nikita Popov
95ad1d1cbc Merge branch 'PHP-8.1'
* PHP-8.1:
  Make DirectoryIterator current() / key() return types tentative
2022-03-12 17:36:52 +01:00
Nikita Popov
d0a0518798 Make DirectoryIterator current() / key() return types tentative
Fixes GH-8192.
2022-03-12 17:32:44 +01:00
Christoph M. Becker
634b2141de Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8121: SplFileObject - seek and key with csv file inconsistent
2022-03-08 16:59:19 +01:00
Christoph M. Becker
3a71fcf5ca Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8121: SplFileObject - seek and key with csv file inconsistent
2022-03-08 16:57:58 +01:00
Christoph M. Becker
1d9a1f9be3 Fix GH-8121: SplFileObject - seek and key with csv file inconsistent
First, we must not free the current line before we call
`spl_filesystem_file_read_csv()`, because then the `current_line` will
not be properly updated.  Since the EOF check is superfluous here, we
move that part of the code to the branch for subtypes.  This issue has
been introduced by the fix for bug 75917.

Second, we only must increase the `current_line` if we're not reading
ahead.  This issue has been introduced by the fix for bug 62004.

Closes GH-8138.
2022-03-08 16:54:02 +01:00
Tyson Andre
b50315e73c Merge branch 'PHP-8.1'
Conflicts:
	ext/spl/tests/fixedarray_023.phpt
	ext/spl/spl_fixedarray.c (fix compile error)
2022-02-23 19:52:59 -05:00
Tyson Andre
5d907dfcee Merge branch 'PHP-8.0' into PHP-8.1 2022-02-23 19:26:24 -05:00
Tyson Andre
cd1c6f0b81 Fixes infinite recursion introduced by patch to SplFixedArray (#8105)
Closes GH-8079

Track whether the spl_fixedarray was modified since the last call to
get_properties
2022-02-23 19:23:00 -05:00
Dmitry Stogov
c77bbcd464 Fixed GH-8041 (php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray) 2022-02-11 16:46:12 +03:00
Dmitry Stogov
a04d181578 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:36:09 +03:00
Dmitry Stogov
a584d12667 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:35:57 +03:00
Dmitry Stogov
52ae6417ca Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray) 2022-02-11 15:33:31 +03:00
Máté Kocsis
a0ba10436c Merge branch 'PHP-8.1'
* PHP-8.1:
  Remove bogus type of $object param in SplObjectStorage::offsetSet()
2021-12-28 18:03:22 +01:00
Máté Kocsis
24be11f632 Remove bogus type of $object param in SplObjectStorage::offsetSet()
This parameter definitely only accepts objects, so we shouldn't explicitly
mark it as mixed. Looks like I accidentally added this type when adding
the tentative return type.

Closes GH-7840
2021-12-28 18:01:26 +01:00
Christoph M. Becker
8683d17619 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-7809: Cloning a faked SplFileInfo object may segfault
2021-12-23 23:15:02 +01:00
Christoph M. Becker
0ed39ed809 Fix GH-7809: Cloning a faked SplFileInfo object may segfault
While the `path` is not supposed to be `NULL` for normal operation, it
is possible to create `SplFileInfo` objects where that is the case, and
we must not follow the null pointer.

Closes GH-7814.
2021-12-23 23:10:51 +01:00
Christoph M. Becker
fd2a6d2360 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix #75917: SplFileObject::seek broken with CSV flags
2021-12-06 19:03:13 +01:00
Christoph M. Becker
6f325104eb Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #75917: SplFileObject::seek broken with CSV flags
2021-12-06 19:02:32 +01:00
Aliaksandr Bystry
daf79e2d91 Fix #75917: SplFileObject::seek broken with CSV flags
Closes GH-7697.
2021-12-06 18:59:48 +01:00
Tyson Andre
024d5f4b63 Cache method overrides of ArrayAccess in zend_class_entry
Previously, code such as subclasses of SplFixedArray would check for method
overrides when instantiating the objects.

This optimization was mentioned as a followup to GH-6552
2021-12-04 11:35:38 -05:00
Tyson Andre
032de9e001 Optimize SplObjectStorage native read/write/has/unset dimension handlers
This makes reading/writing with `$splObjectStorage[$offset]` shorthand twice as
fast as it was previously, and a bit faster than offsetGet/offsetSet instead of
(previously) much slower.

Call destructor after overriding old SplObjectStorage entry.
Previously, it was called before, which was possibly unsafe
if the destructor had side effects.

Add tests.

Closes GH-7695

Related to GH-7690

Check for ref in SplObjectStorage->__unserialize, check for ref.

SplObjectStorage->unserialize may be a different cause of references
for malformed inputs, so continue checking

In internally used methods, convert references to non-references if they're
found.
2021-11-30 09:09:12 -05:00
Nikita Popov
902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00
Remi Collet
bc9d604430 Merge branch 'PHP-8.1'
* PHP-8.1:
  fix [-Wstrict-prototypes] buid warnings
2021-11-24 14:55:30 +01:00
Remi Collet
ef2fd0e5b5 fix [-Wstrict-prototypes] buid warnings 2021-11-24 14:55:11 +01:00
Nikita Popov
8a7f9a5c38 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81587
2021-11-04 10:38:59 +01:00
Nikita Popov
d7ad32649a Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed bug #81587
2021-11-04 10:38:08 +01:00