htmlspecialchars() allocated a buffer of twice the input and decoded it
character by character, even when the result was the input itself.
The input is now scanned first for the characters that need encoding and
for invalid multi-byte sequences, with SSE2 on 16-byte blocks. When there
is none, the input string is returned, as html_entity_decode() and
htmlspecialchars_decode() already do since 68dc754998. Otherwise, encoding
starts after the part that was scanned.
The @refcount 1 annotations of htmlspecialchars() and htmlentities() are
removed since they can now return their argument.
Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
The function either throws on an invalid callback or appends the entry
to the tick list and returns true; php_add_tick_function() returns void,
so there is nothing that could report a failure.
The function has a single non-throwing exit, RETURN_TRUE (main/SAPI.c).
The false return disappeared in PHP 8.0.0: until then an invalid callback
was rejected with RETURN_FALSE, whereas the zend_parse_parameters() 'f'
specifier introduced there throws a TypeError. Registering a callback
after the headers have been sent, the one case where the callback is
knowingly discarded, also returns true.
ksort(), asort() and natsort() already declare true in the same stub.
Both are single-argument wrappers around zend_string_tolower/upper;
static analyzers and general string handling call them at very high
frequency. The frameless call convention removes the call frame setup
and argument copying.
Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
Closes GH-23084
On a non-blocking stream, stream_socket_enable_crypto() returns 0 and
fread()/fwrite() return an empty result when the TLS engine needs more
I/O, but there was no way to tell whether OpenSSL was waiting to read or
to write. Callers therefore could not reliably decide which direction to
poll for with stream_select(), which is required to drive a non-blocking
handshake or renegotiation correctly (e.g. SSL_read() wanting a write).
This tracks the last SSL_ERROR_WANT_READ/WANT_WRITE on the stream and
exposes it via a new stream_socket_get_crypto_status() function and three
constants:
STREAM_CRYPTO_STATUS_NONE
STREAM_CRYPTO_STATUS_WANT_READ
STREAM_CRYPTO_STATUS_WANT_WRITE
The status is updated during the handshake (php_openssl_enable_crypto())
and during reads/writes (php_openssl_sockop_io()), reset to NONE before
each operation, and retrieved through a new STREAM_XPORT_CRYPTO_OP_GET_STATUS
transport op. It is meaningful immediately after an operation that
returned 0/false on a non-blocking stream; a completed operation reports
NONE.
Tests cover the status during a non-blocking handshake, a non-blocking
read with no application data pending, and the constant values.
This introduces new stream error handling that allows configurable
handling of stream errors. This can be configured in stream contex.
All streams, ext/standard and ext/phar stream errors are converted to
use the new API.
RFC: https://wiki.php.net/rfc/stream_errors
Closes GH-20524
Functions that use zend_forbid_dynamic_call() must be flagged with
ZEND_ACC2_FORBID_DYN_CALLS. In stubs, this is done by using
@forbid-dynamic-calls.
To ensure consistency, we assert that the flag exists in
zend_forbid_dynamic_call(), and we assert that flagged functions thrown after a
dynamic call.
Closes GH-21818
Change zend_function_entry.flags to a uint64_t to that both ZEND_ACC_ and
ZEND_ACC2_ flags can be represented.
Introduce ZEND_FENTRY_FLAGS(flags, flags2) to pass ZEND_ACC2_ flags to
ZEND_RAW_FENTRY(), ZEND_FENTRY().
Source-level backwards compatibility is maintained, as passing raw ZEND_ACC_
flags to ZEND_RAW_FENTRY(), ZEND_FENTRY() still works.
Follow-up to GH-21100, that mistakenly set the default value of
the `array_filter()` as `ARRAY_FILTER_USE_KEY`, when it should
be `ARRAY_FILTER_USE_VALUE`, which is the newly defined constant.
Update gen_stubs.php to generate C enums from internal enums, when the stub is annotated with @generate-c-enums. Enum values can be compared to the result of zend_enum_fetch_case_id(zend_object*).
The generated enums are added to separate files named {$extensionName}_decl.h, so that it's possible to include these from anywhere. _arginfo.h files would generate warnings if we tried to include them in a compilation unit that doesn't call the register_{$class} functions, for instance.
Introduce Z_PARAM_ENUM().
* Make ZEND_AST_CONST_ENUM_INIT a 4-children node
* Store enum case id in ZEND_AST_CONST_ENUM_INIT
* Store enum case id in instance
* Expose enum case_id internally
* Generate C enum for internal enums
* Introduce Z_PARAM_ENUM()
* Port extensions
In GH-15647, the `array_filter` function was changed to throw a
`ValueError` exception when the `$mode` parameter receives an
invalid.
Additionally, it declares a new `ARRAY_FILTER_USE_VALUE`, assigned
(`int 1`) to it.
This changes the default value of the `array_filter` function's
`$mode` parameter to use the new constant, changing it from
`int $mode = 0` to `int $mode = ARRAY_FILTER_USE_KEY)`.
Closes GH-21100.
* Implement clamp function
Co-authored-by: thinkverse <hallberg.kim@gmail.com>
* - Use a common function for normal and frameless implementations
- Add tests for null and not-comparable cases
- Fix object support for frameless clamp function
- Improve NAN handling
* Create tests triggering both frameless and dynamic variants
* Add changelog
* [Review] rephrase error messages to use "must not"
* Enable assert()
---------
Co-authored-by: thinkverse <hallberg.kim@gmail.com>
This is modelled similarly to the password registry API.
We have an array to which new handlers can be added, and when a built-in
handler cannot handle the image, we try the handlers in the array.
The standard module is in control of registering a new constant for the
image file type so that no clashes can occur. It also updates the image
file type count constant. As such, the registration may only happen
during module startup.
Only covers constants declared via stub files, others will be handled
separately in a later commit.
Does not include the intl extension, since that had some errors relating to the
cpp code; that extension will be updated separately.
When the array functions perform their operation in-place, the
`@refcount 1` annotation is wrong and causes a failure under
`ZEND_VERIFY_FUNC_INFO`.
The test file tests all functions that have the in-place optimization,
even those that didn't have the refcount annotation, just to prevent
future regressions.
Closes GH-18929.
* Move glob to main/ from win32/
In preparation to make the Win32 reimplementation the standard
cross-platform one. Currently, it doesn't do that and just passes
through the original glob implementation. We could consider also having
an option to use the standard glob for systems that have a sufficient
one.
* Enable building with win32 glob on non-windows
Kind of broken. We're namespacing the function and struct, but not yet
the GLOB_* defines. There are a lot of places callers check if i.e.
NOMATCH is defined that would likely become redundant.
Currently it also has php_glob and #defines glob php_glob (etc.) - I
suspect doing the opposite and changing the callers would make more
sense, just doing MVP to geet it to build (even if it fails tests).
* Massive first pass at conversion to internal glob
Have not tested yet. the big things are:
- Should be invisible to userland PHP code.
- A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result,
especially in comments.
- Prefixes everything with PHP_ to avoid conflicts with system glob in
case it gets included transitively.
- A lot of weird shared definitions that were sprawled out to other
headers are now included in php_glob.h.
- A lot of (but not yet all cases) of HAVE_GLOB are removed, since we
can always fall back to php_glob.
- Using the system glob is not wired up yet; it'll need more shim
ifdefs for each flag type than just glob_t/glob/globfree defs.
* Fix inclusion of GLOB_ONLYDIR
This is a GNU extension, but we don't need to implement it, as the GNU
implementation is flawed enough that callers have to manually filter it
anyways; just provide a stub definition for the constant.
We could consideer implementing this properly later. For now, fixes the
basic glob constant tests.
* Remove HAVE_GLOBs
We now always have a glob implementation that works. HAVE_GLOB should
only be used to check if we have a system implementation, for if we
decide to wrap the system implementation instead.
* We don't need to care about being POSIXly correct for internal glob
* Check for reallocarray
Ideally temporary until GH-17433.
* Forgot to move this file from win32/ to main/
* Check for issetugid (BSD function)
* Allow using the system glob with --enable-system-glob
* Style fix after removing ifdef
* Remove empty case for system glob
* ext/standard: change `highlight_string()` return type from `string|bool` to `string|true`
* ext/standard: change `print_r` return type from `string|bool` to `string|true`