Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds. This may be useful for other compilers as well.
FR #79344: xmlwriter_write_attribute_ns: $prefix should be nullable
The `$prefix` parameter of `xmlwriter_write_element_ns()` and
`xmlwriter_start_element_ns()` is nullable, what allows these functions
to be used instead of their non NS variants. Consequently, we make the
`$prefix` parameter of `xmlwriter_write_attribute_ns()` and
`xmlwriter_start_attribute_ns()` nullable as well.
Even if the length of a maker note does not match our expectations
(either because the maker note is corrupted, or because our
expectations do not quite match reality), there is no need to let
parsing fail; we can still go on parsing the other meta information.
Nikita Popov [Fri, 12 Jun 2020 12:57:08 +0000 (14:57 +0200)]
Use GC stack in nested data removal
We should be doing this anyway to prevent stack overflow, but on
master this is important for an additional reason: The temporary
GC buffer provided for get_gc handlers may get reused if the scan
is performed recursively instead of indirected via the GC stack.
Nikita Popov [Fri, 12 Jun 2020 10:52:39 +0000 (12:52 +0200)]
Avoid out of range float to int cast in exif
Use convert_any_int instead of convert_any_format to directly get
an integer.
Also adjust SRATIONAL handling to not go through a double division.
This was introduced to avoid SIGFPE for the INT_MIN / -1 case,
but we can just handle that explicitly.
Nikita Popov [Fri, 12 Jun 2020 08:18:19 +0000 (10:18 +0200)]
Use unused attribute for _dummy
The (void)_dummy is apparently considered a read of an uninitialized
variable. As it is a _Bool now, which has trap representations, this
is no longer considered legal and results in somewhat odd ubsan
warnings of the form:
runtime error: load of value 0, which is not a valid value for type 'zend_bool' (aka 'bool')
Anatol Belski [Thu, 11 Jun 2020 11:09:00 +0000 (13:09 +0200)]
sqlite3: Fix possible use after free
Exception should be thrown before the db handle is destroyed.
The backtrace excerpt
==26628== Invalid read of size 4
==26628== at 0x53C49E3: sqlite3_errmsg (in /usr/lib64/libsqlite3.so.0.8.6)
==26628== by 0x38C4E9: zim_sqlite3_open (sqlite3.c:142)
==26628== by 0x8977BF: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==26628== by 0x8F801E: execute_ex (zend_vm_execute.h:53824)
==26628== by 0x8FC0BB: zend_execute (zend_vm_execute.h:57920)
==26628== by 0x828F54: zend_execute_scripts (zend.c:1672)
==26628== by 0x793C2C: php_execute_script (main.c:2621)
==26628== by 0x8FEA44: do_cli (php_cli.c:964)
==26628== by 0x8FF9DC: main (php_cli.c:1359)
The output normalization of bless_tests.php only detected absolute Unix
filenames; we extend this for absolute Windows filenames, regardless of
the platform we're running on (tests may have been run on Windows, but
bless_tests.php may be run from WSL or a Linux VM, for instance).
Nikita Popov [Wed, 10 Jun 2020 08:25:50 +0000 (10:25 +0200)]
Fix bug #65006
The "callable name" may be the same for multiple distinct callables.
The code already worked around this for the case of instance methods,
but there are other cases in which callable names clash, such as
the use of self:: reported in the referenced bug.
Rather than trying to generate a unique name for callables, compare
the content of the alfi structures. This is less efficient if there
are many autoload functions, but autoload *registration* does not
need to be particularly efficient.
As a side-effect, this no longer permits unregistering non-callables.
Nikita Popov [Wed, 10 Jun 2020 08:03:43 +0000 (10:03 +0200)]
Remove called_scope inheritance in zend_call_method()
Similar to 097043db2a0d113f89bd26c6f1d7a976d83951a8, but for the
zend_call_method() API. I don't think we ever use this for
static methods, but this logic shouldn't be there. If you want
to inherit the active LSB scope for some reason, do so explicitly.
Nikita Popov [Wed, 10 Jun 2020 07:55:50 +0000 (09:55 +0200)]
Fix called scope assignment in autoloader
We should use the scope specified in the spl_autoload_register()
call, not whatever LSB scope just so happens to be active at the
time of the autoloader call.
Nikita Popov [Wed, 10 Jun 2020 07:41:58 +0000 (09:41 +0200)]
Remove autoload_running flag
This was only used to decide between a hash clean and a hash
destroyed in spl_autoload_remove(). But now that
spl_autoload_functions() no longer distinguishes between NULL and
an empty array here, there's really no need to try and destroy
the hashtable here.
Nikita Popov [Tue, 9 Jun 2020 15:36:36 +0000 (17:36 +0200)]
Cleanup SPL autoload implementation
Replace EG(autoload_func) with a C level zend_autoload hook.
This avoids having to do one indirection through PHP function
calls. The need for EG(autoload_func) was a leftover from the
__autoload() implementation.
Additionally, drop special-casing of spl_autoload(), and instead
register it just like any other autoloading function. This fixes
bug #71236 as a side-effect.
Finally, change spl_autoload_functions() to always return an array.
The distinction between false and an empty array no longer makes
sense here.
Control VCRT leak reporting via environment variable in debug builds
Formerly, this had to be enabled by passing the configuration flag
`--enable-crt-debug`; now it can be enabled by setting the environment
variable `PHP_WIN32_DEBUG_HEAP`. The advantage is that it is no longer
necessary to do separate builds, at the cost of a very minor
performance penalty during process startup.
In module startup stage, we should not initiliaze
EG(modified_ini_directives) as it use zend MM, the zend MM will be
restart at the end of modules startup stage,
by say "partial", because this issue still exists if altering ZEND_USER
inis, we should add a zend_ini_deactive at the end of modules startup
stage, but it brings some new cost, and I think no one would do things
like that
For snapshot builds (`--enable-snapshot-build`), after the build has
been completely finished, running `nmake` causes a lot of DLLs to be
rebuilt. The problem is that the build folders OptimizerObj and
opcache_jit are dependencies of the main PHP DLL, but these folders do
not exists in the source tree, so nmake assumes it has to re-link the
main PHP DLL, and that makes several other DLLs stale.
We solve that by mirroring the folder structure of the respective
source folders.
The `timercmp()` manpage[1] points out that some systems have a broken
implementation which does not support `>=`. This is definitely the
case for the Windows SDK, which only supports `<` and `>`.
Nikita Popov [Tue, 9 Jun 2020 14:30:46 +0000 (16:30 +0200)]
Back up fake_scope in zend_call_function
We regularly find new places where we forgot to reset fake_scope.
Instead of having to handle this for each caller of zend_call_function()
and similar APIs, handle it directly in zend_call_function().
These are used to perform a call if you already have the
zend_function you want to call. zend_call_known_function()
is the base API, the rest are just really thin wrappers around
it for the common case of instance method calls.