Commit graph

525 commits

Author SHA1 Message Date
Niels Dossche
e3433fdaef
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18421: Integer overflow with large numbers in LimitIterator
2025-04-25 20:06:24 +02:00
Niels Dossche
4ff41cfb4b
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18421: Integer overflow with large numbers in LimitIterator
2025-04-25 20:06:18 +02:00
Niels Dossche
a91d913901
Fix GH-18421: Integer overflow with large numbers in LimitIterator
Since we already know that `pos < intern->u.limit.offset` at this point,
we can reverse the expression.

Closes GH-18424.
2025-04-25 20:05:55 +02:00
Kalle Sommer Nielsen
ed320b500c Fix C23 syntax for VS16 (CI runs VS22) 2025-01-31 22:28:31 +02:00
Gina Peter Banyard
7c32e41ab8 ext/spl: Refactor iterator_apply() to not rely on an FCI
This reduces the size of the struct from 112 to 56 bytes
2025-01-05 12:27:28 +00:00
Gina Peter Banyard
e547fe40df ext/spl: Remove useless obj field from spl_iterator_apply_info 2025-01-05 12:27:28 +00:00
Niels Dossche
aafcf997f9
Use spl_RecursiveIteratorIterator_free_iterators() 2024-11-01 20:46:29 +01:00
Niels Dossche
7a78ffcbb2
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16604: Memory leaks in SPL constructors
2024-11-01 20:43:43 +01:00
Niels Dossche
eaa2b61acb
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16604: Memory leaks in SPL constructors
2024-11-01 20:43:28 +01:00
Niels Dossche
886a5287ca
Fix GH-16604: Memory leaks in SPL constructors
Closes GH-16673.
2024-11-01 20:42:28 +01:00
Gina Peter Banyard
54047c1090 ext/spl: Remove some useless header includes and clarify usages 2024-06-15 01:33:09 +01:00
Gina Peter Banyard
a5cacba6d8
ext/spl: Remove spl_engine.h header (#14418)
And convert calls to spl_instantiate_arg_* to the new object_init_with_constructor() API
2024-06-08 23:46:34 +01:00
Gina Peter Banyard
fd2d869642
Clean-up some more headers (#14416)
Remove unused headers (such as php_ini.h for extensions that don't define INI settings)
Use more specific headers when possible
2024-06-08 17:15:36 +01:00
Levi Morrison
07a1921a8c
refactor: use ZEND_PARSE_PARAMETERS_NONE() (#14442)
Prefer:

	ZEND_PARSE_PARAMETERS_NONE();

Over:

	if (zend_parse_parameters_none() == FAILURE) {
		RETURN_THROWS();
	}

It's shorter, more modern, and they do the same thing. Technically,
ZEND_PARSE_PARAMETERS_NONE doesn't check that there's an exception,
but it generates one, so it's still cohesive.
2024-06-02 23:58:24 +01:00
Levi Morrison
c461b60060
refactor: change zend_is_true to return bool (#14301)
Previously this returned `int`. Many functions actually take advantage
of the fact this returns exactly 0 or 1. For instance,
`main/streams/xp_socket.c` does:

    sockopts |= STREAM_SOCKOP_IPV6_V6ONLY_ENABLED * zend_is_true(tmpzval);

And `Zend/zend_compile.c` does:

    child = &ast->child[2 - zend_is_true(zend_ast_get_zval(ast->child[0]))];

I changed a few places trivially from `int` to `bool`, but there are
still many places such as the object handlers which return `int` that
should eventually be `bool`.
2024-05-24 15:16:36 -06:00
Cristian Rodríguez
8e62e2b829
Mark multple functions as static (#13864)
* Mark many functions as static

Multiple functions are missing the static qualifier.

* remove unused struct sigactions

struct sigaction act, old_term, old_quit, old_int;
all unused.

* optimizer: minXOR and maxXOR are unused
2024-05-22 13:11:46 +02:00
Niels Dossche
e16bc4b28e
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14290: Member access within null pointer in extension spl
2024-05-21 23:24:28 +02:00
Niels Dossche
88af09193d
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14290: Member access within null pointer in extension spl
2024-05-21 23:24:15 +02:00
Niels Dossche
b3a56bd558
Fix GH-14290: Member access within null pointer in extension spl
php_pcre_replace_impl() can fail and return NULL. We should take that
error condition into account. Because other failures return false, we
return false here as well.

At first, I also thought there was a potential memory leak in the error
check of replacement_str, but found that the error condition can never
trigger, so replace that with an assertion.

Closes GH-14292.
2024-05-21 23:20:32 +02:00
David CARLIER
9726721560
general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00:00
Niels Dossche
642e11140c
Minor pcre optimizations (#12923)
* Update signature of pcre API

This changes the variables that are bools to actually be bools instead
of ints, which allows some additional optimization by the compiler (e.g.
removing some ternaries and move extensions).

It also gets rid of the use_flags argument because that's just the same
as flags == 0. This reduces the call frame.

* Use zend_string_release_ex where possible

* Remove duplicate symbols from strchr

* Avoid useless value conversions

* Use a raw HashTable* instead of a zval

* Move condition

* Make for loop cheaper by reusing a recently used value as start iteration index

* Remove useless condition

This can't be true if the second condition is true because it would
require the string to occupy the entire address space.

* Upgrading + remark
2023-12-11 19:43:26 +01:00
Niels Dossche
4cfc8f6d7a
Remove dead stores from ext/spl (#12550) 2023-10-29 14:42:23 +00:00
George Peter Banyard
e41598c7fc ext/spl: Use new F ZPP modifier 2023-10-10 13:44:21 +01:00
Ilija Tovilo
04fd04acab
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix reference returned from CallbackFilterIterator::accept()
2023-04-20 13:43:29 +02:00
Ilija Tovilo
b2282bee32
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix reference returned from CallbackFilterIterator::accept()
2023-04-20 13:43:20 +02:00
Ilija Tovilo
5855bdcd6c
Fix reference returned from CallbackFilterIterator::accept()
Fixes oss-fuzz #58181
2023-04-20 10:18:18 +02:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Niels Dossche
2b15061fbb
Use zend_result in ext/spl where appropriate (#10734)
* Convert functions in spl_heap to return zend_result

* Convert functions in spl_iterators to return zend_result
2023-03-01 18:58:17 +01:00
Marcos Marcolin
9004725367
chore: standardize the visibility of functions. (#10708)
Co-authored-by: Marcos Marcolin <marcos@ixcsoft.com.br>
2023-02-26 14:08:33 +00:00
George Peter Banyard
32d3cae19f
Handle trampolines correctly in new FCC API + usages (#9877) 2022-11-22 17:12:53 +00:00
George Peter Banyard
8d5d3fd035 Refactor SPL Callback filter to only use FCC 2022-11-02 14:52:54 +00:00
George Peter Banyard
66661ae682
Remove most usages of zend_fcall_info_args()
This reallocates the PHP array when one can just use the named_params fields to pass the positional arguments instead.

Only usage of zend_fcall_info_args(_ex) remains in PDO.
2022-10-21 18:31:40 +01:00
George Peter Banyard
1ea1b6319e Use zend_call_function_with_return_value() in SPL iterators 2022-10-21 17:26:21 +01:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Máté Kocsis
b73f139c70
Declare ext/spl constants in stubs (#9226) 2022-08-02 16:37:12 +02:00
Tim Düsterhus
7ae7df5b46
RFC: Make the iterator_*() family accept all iterables (#8819)
https://wiki.php.net/rfc/iterator_xyz_accept_array
2022-07-19 16:46:32 +02: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
cfc38a6014
SPL: minor refactoring (#8341)
Use more appropriate types and return macros
2022-04-13 20:34:23 +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
Nikita Popov
eac65680ab Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix leak when iterating uninitialized RecursiveIteratorIterator
2021-09-24 13:18:00 +02:00
Nikita Popov
3adbafeef7 Fix leak when iterating uninitialized RecursiveIteratorIterator 2021-09-24 13:17:34 +02:00
Nikita Popov
6d505d4445 Add RETURN/RETVAL_COPY_DEREF() macros
These were missing from the set...

I think quite a few of these usages don't actually need the DEREF,
but I've just kept things as is for now.
2021-07-22 09:44:19 +02:00
Nikita Popov
c2b29308ff Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix RecursiveIteratorIterator segfault for invalid aggregate
2021-07-15 13:11:39 +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
Nikita Popov
11f62c989e Revert "IteratorIterator::getInnerIterator() can't return null"
This reverts commit c252420d08.

This (currently) does not hold for invalid AppendIterators,
revert for now.
2021-07-15 11:01:28 +02:00
Nikita Popov
c252420d08 IteratorIterator::getInnerIterator() can't return null
If ther IteratorIterator is initialized (which we check), then
zobject cannot be undef and the return value cannot be null.
2021-07-15 10:42:34 +02:00
Nikita Popov
f7b1238f13 Handle out of order destruction of RecursiveIteratorIterator 2021-07-02 17:14:00 +02:00