Commit Graph

2483 Commits

Author SHA1 Message Date
Tyson Andre
753645a6f8 Merge remote-tracking branch 'origin/PHP-7.4' into PHP-8.0 2021-09-13 21:00:53 -04:00
Tyson Andre
b053192a03
Fix #81429: Handle resizing in SplFixedArray::offsetSet (#7487)
offsetSet did not account for the fact that the array may no longer exist after
the field is overwritten. This fixes that.

Add test of resizing both to the empty array and a smaller array - there should
be no valgrind warnings with a proper fix.

Alternate approach to #7486 (described in https://bugs.php.net/bug.php?id=81429)
2021-09-13 20:59:06 -04:00
Máté Kocsis
fc6656e0ac
Fix some more ext/spl return types
Closes GH-7242
2021-07-15 16:40:29 +02:00
Nikita Popov
b9ae73eee9 Fix RecursiveIteratorIterator segfault for invalid aggregate
The code was assuming that the returned value is an object.
Reuse the logic from IteratorIterator.
2021-07-15 13:11:28 +02:00
Máté Kocsis
d618ed0a2d
Fix some return types in ext/spl
Closes GH-7237
2021-07-14 12:33:14 +02:00
Máté Kocsis
80e5ad5a29
Various ext/spl stub fixes
Closes GH-7215
2021-07-12 10:27:05 +02:00
Nikita Popov
bcefc31e4e Fix ArrayObject::exchangeArray() return type
This method cannot return null.
2021-07-06 10:52:08 +02:00
Christoph M. Becker
80f921d7e0
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80933: SplFileObject::DROP_NEW_LINE is broken for NUL and CR
2021-04-13 16:49:57 +02:00
Christoph M. Becker
976e71a2fa
Fix #80933: SplFileObject::DROP_NEW_LINE is broken for NUL and CR
`buf` may contain NUL bytes, so we must not use `strcspn()` but rather
a binary safe variant.  However, we also must not detect a stray CR as
line ending, and since we only need to check line endings at the end
of the buffer, we can nicely optimize.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>

Closes GH-6836.
2021-04-13 16:49:06 +02:00
Dmitry Stogov
957cb13a49 Fixed bug #80802: (zend_jit_fetch_indirect_var assert failure with tracing JIT) 2021-03-01 23:57:20 +03:00
Nikita Popov
8e9eeca0b3 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix leak when breaking out of FilesystemIterator
2021-02-15 10:38:21 +01:00
Nikita Popov
44a80b64b9 Fix leak when breaking out of FilesystemIterator
We need to always destroy current, not just when iter.data is not
set.

Take this opportunity to clean up the iterator destructor code a
bit, to remove redundant checks and incorrect comments.
2021-02-15 10:37:59 +01:00
Nikita Popov
226395a335 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #80719
2021-02-11 16:13:56 +01:00
Nikita Popov
c34c523467 Fixed bug #80719 2021-02-11 16:12:06 +01:00
Nikita Popov
f2364f316d SplFileObject::fgets() cannot return false
spl_filesystem_file_read() is called with silent=0, so it will
throw on failure.
2021-01-18 16:47:21 +01:00
Christoph M. Becker
f1d11c118d Fix #62004: SplFileObject: fgets after seek returns wrong line
As it is, `::seek(0)` sets the file pointer to the beginning of the
file, but `::seek($n)` where `$n > 0` sets the file pointer to the
beginning of the following line, having line `$n` already read into the
line buffer.  This is pretty inconsistent; we fix it by always seeking
to the beginning of the line.

We also add a test case for the duplicate bug #46569.

Closes GH-6434.
2020-11-30 16:03:37 +01:00
Nikita Popov
0535872b7c Use separate directory in dit_004.phpt
Make sure the directory is not modified while we're iterating it,
which may give unstable results.
2020-10-26 09:26:18 +01:00
Nikita Popov
bfe7a1168a Properly validate ArrayObject::asort() argument 2020-10-22 15:20:43 +02:00
Nikita Popov
61b33e900c Add additional initialization checks to SplFileInfo 2020-10-19 10:35:22 +02:00
Nikita Popov
68195bd481 Update ext/spl parameter names
Closes GH-6284.
2020-10-07 12:26:46 +02:00
Nikita Popov
2c1b5c4365 Support GC for AppendIterator
This also requires adding GC support for ArrayIterator internal
iterators.
2020-10-01 16:18:23 +02:00
Nikita Popov
afab9eb48c Fix bug #65387
Add GC support to dual_it. This is still missing AppendIterator
support.
2020-10-01 16:12:56 +02:00
Levi Morrison
3b34d74a45 Clean up spl_fixedarray.c
Remove inline.
Remove old folding blocks.
Convert an int usage to bool.

Convert some uses of int and size_t into zend_long. This is
incomplete because get_gc requires `int *n`, which should probably
become zend_long or size_t eventually.

Adds spl_fixedarray_empty to help enforce invariants.
Adds spl_fixedarray_default_ctor.
Documents some functions.

Reworks spl_fixedarray_copy into two functions:
  - spl_fixedarray_copy_ctor
  - spl_fixedarray_copy_range

I'm hoping to eventually export SplFixedArray for extensions to
use directly, which is the motivation here.
2020-09-27 12:25:02 -06:00
Nikita Popov
9428e161a8 Add option to print parameter name stats to gen_stub 2020-09-24 15:16:29 +02:00
Nikita Popov
625d8463a4 Consistent error handling for fgetcsv/fputcsv
Normalize the behavior between the file functions and those on
SplFileObject.

Be consistent about throwing regardless of whether the delimiter etc
is empty or has too many characters. I don't think it's worthwhile
to distinguish these cases.

Back when we looked into this originally, there was some hope that
we might want to add support for multiple-character delimiter etc,
but after a cursory look, I really don't think this is going to
happen (for fputcsv maybe, but for fgetcsv this just makes an already
broken function much more complicated.)

Closes GH-6188.
2020-09-23 10:11:04 +02:00
Alex Dowad
4222ae16e7 SplFixedArray is Aggregate, not Iterable
One strange feature of SplFixedArray was that it could not be used in nested foreach
loops. If one did so, the inner loop would overwrite the iteration state of the outer
loop.

To illustrate:

    $spl = SplFixedArray::fromArray([0, 1]);
    foreach ($spl as $a) {
      foreach ($spl as $b) {
        echo "$a $b";
      }
    }

Would only print two lines:

    0 0
    0 1

Use the new InternalIterator feature which was introduced in ff19ec2df3 to convert
SplFixedArray to an Aggregate rather than Iterable. As a bonus, we get to trim down
some ugly code! Yay!
2020-09-23 08:33:24 +02:00
Nikita Popov
fb4554e431 Throw warning for failed object to int/float conversion
We previously couldn't increase the error level here because it
was coupled to comparison handling. This is no longer the case
in PHP 8.
2020-09-21 17:04:39 +02:00
Máté Kocsis
e95fa3eb0c
Fix a few Iterator signatures
Closes GH-6176
2020-09-21 16:03:09 +02:00
Máté Kocsis
64af12d13b
Add support for @implementation-alias in stubs
Closes GH-6170
2020-09-21 10:08:45 +02:00
Nikita Popov
c5401854fc Run tidy
This should fix most of the remaining issues with tabs and spaces
being mixed in tests.
2020-09-18 14:28:32 +02:00
Máté Kocsis
36fd95b524
Generate arginfos 2020-09-16 21:28:27 +02:00
Máté Kocsis
de912821e0
Display string default values in stubs more uniformly
Settling on using quoted string
2020-09-16 21:27:01 +02:00
Máté Kocsis
c76910cd96
Display types in stubs more uniformly
In preparation for generating method signatures for the manual.

This change gets rid of bogus false|null return types, a few unnecessary trailing backslashes, and settles on using ? when possible for nullable types.
2020-09-16 21:19:36 +02:00
George Peter Banyard
063fdd9422 Use ValueError instead of exceptions in SPL extension 2020-09-15 12:49:59 +02:00
George Peter Banyard
b6207338e8 Use normal error in SPL for uninitialized objects 2020-09-15 12:49:59 +02:00
George Peter Banyard
9affbef0e6 Use normal error in SPL for 'An iterator cannot be used with foreach by reference' 2020-09-15 12:49:59 +02:00
Larry Garfield
96f2f3174b Update array parameter names for named parameters
* The array "subject" of a function gets called $array.

* Further parameters should be self-descriptive if used
  as a named parameter, and a full word, not an abbreviation.

* If there is a "bunch more arrays" variadic, it gets
  called $arrays (because that's what was already there).

* A few functions have a variadic "a bunch more arrays,
  and then a callable", and were already called $rest.
  I left those as is and died a little inside.

* Any callable provided to an array function that acts
  on the array is called $callback. (Nearly all were already,
  I just fixed the one or two outliers.)

* array_multisort() is beyond help so I ran screaming.
2020-09-14 14:56:49 +00:00
Máté Kocsis
9975986b7e
Improve error messages mentioning parameters instead of arguments
Closes GH-5999
2020-09-09 10:47:43 +02:00
Nikita Popov
7e339a335e Make null byte error a ValueError
Currently we treat paths with null bytes as a TypeError, which is
incorrect, and rather inconsistent, as we treat empty paths as
ValueError. We do this because the error is generated by zpp and
it's easier to always throw TypeError there.

This changes the zpp implementation to throw a TypeError only if
the type is actually wrong and throw ValueError for null bytes.
The error message is also split accordingly, to be more precise.

Closes GH-6094.
2020-09-08 15:23:23 +02:00
Máté Kocsis
628db3f3b5
Fix UNKNOWN default values in various extensions
Closes GH-6075
2020-09-07 19:02:02 +02:00
Máté Kocsis
8107a1da5a
Use ZPP instead of custom type checks
We can add these types as a native type declaration to stubs as a side-effect. Closes GH-6068
2020-09-04 14:32:34 +02:00
George Peter Banyard
7805b97720 Extract common flock code
As SPL is currently a copie of the code in file.c

Closes GH-6069
2020-09-04 14:29:31 +02:00
Nikita Popov
2e218180ef Release call trampolines in zpp fcc
When using zpp 'f' or Z_PARAM_FUNC, if the fcc points to a call
trampoline release it immediately and force zend_call_function
to refetch it. This may require additional callability checks
if __call is used, but avoids the need to carefully free fcc
values in all internal functions -- in some cases this is not
simple, as a type error might be triggered by a later argument
in the same zpp call.

This fixes oss-fuzz #25390.

Closes GH-6073.
2020-09-04 14:23:14 +02:00
George Peter Banyard
61c299fe9c Error promotions in SPL
Warning to Error promotion and a Notice to Warning promotion to align
with the behaviour specified in the Reclassify Engine Warnings RFC.

Closes GH-6072
2020-09-03 19:27:02 +02:00
George Peter Banyard
430b3ac7df Refactor parts of SPL Dir/SplFileObject
This fixes a way it was possible to trigger an Internel Error
by disabling function (via the INI setting) when SPL was acting
as a proxy to the function call.

Fix flock_compat layer as it needs to used in SPL now.

Use macro to check if object is initialized

Closes GH-6014
2020-09-03 14:23:18 +02:00
Máté Kocsis
f7fbc6333f
Add more precise type info for stubs
Closes GH-6005
2020-09-01 16:35:56 +02:00
Nikita Popov
f965e20059 Promote ArrayObject modification during sorting to Error exception 2020-08-28 10:42:14 +02:00
Nikita Popov
a3d0d947bd Use zend_dval_to_lval() in spl_offset_convert_to_long()
Avoid fptoi UB and use the standard PHP conversion behavior.
2020-08-27 14:53:56 +02:00
Dmitry Stogov
8c90002201 Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling()) 2020-08-18 11:08:04 +03:00
Nikita Popov
07539685b9 Return empty string from SplFileInfo::getPathname()
Instead of false. This is consistent with how other methods like
SplFileInfo::getPath() behave. It's also a requirement before
SplFileInfo::__toString() calls SplFileInfo::getPathname() and
needs to return a string.
2020-08-14 11:09:30 +02:00