Adding one more [1] exit early safeguard in *nix build scripts:
Given the initial cd into the build tree fails (the project root),
the `buildconf` script exits with non-zero status (failure).
Additionally quoting the pathname to cd into and the empty CD_PATH
parameter for portability, also for systems that are using a
non-portable pathname [2] for the build tree.
[1]: https://github.com/php/php-src/pull/16717
[2]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271
Closes GH-16724.
Show the correct parameter names and numbers - the errors are caused by the
second parameter being empty or having null bytes, not the first.
close GH-15755
Currently, internal classes are registered with the following code:
INIT_CLASS_ENTRY(ce, "InternalClass", class_InternalClass_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ...;
This has worked well so far, except if InternalClass is readonly. It is because some inheritance checks are run by zend_register_internal_class_ex before ZEND_ACC_READONLY_CLASS is added to ce_flags.
The issue is fixed by adding a zend_register_internal_class_with_flags() zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.3 and below.
The pcre is a required dependency in fileinfo extenstion. This marks it
as a configure step dependency for consistency with other extensions
and to have extensions properly sorted in the generated
internal_functions* files.
This test fails over and over again every time we update the library or
because of small changes elsewhere. This leads to a cycle of test
failures and us bumping the values again. This test has little value so
I propose to just get rid of it.
Fixes GH-13795.
- Shebang added so it can be called with ./generate_patch.sh
- Script changes its working directory to ext/fileinfo (where it is
located) so it can be also called as ./ext/fileinfo/generate_patch.sh
- Syntax adjusted a bit for using Bourne or a compatible shell (/bin/sh)
- Downloaded files added to .gitignore
The LICENSE file of libmagic had been inadvertently removed when the
lib had been upgraded to 5.43. So we add the file `COPYING` from that
release[1], and rename it to `LICENSE`.
[1] <https://github.com/file/file/releases/tag/FILE5_43>
Closes GH-14917.
* Include from build dir first
This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.
Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :
-I$(top_builddir)/main
-I$(top_srcdir)
-I$(top_builddir)/TSRM
-I$(top_builddir)/Zend
-I$(top_srcdir)/main
-I$(top_srcdir)/Zend
-I$(top_srcdir)/TSRM
-I$(top_builddir)/
As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.
After this change, the include path is defined as follows:
-I$(top_builddir)/main
-I$(top_builddir)
-I$(top_srcdir)/main
-I$(top_srcdir)
-I$(top_builddir)/TSRM
-I$(top_builddir)/Zend
-I$(top_srcdir)/Zend
-I$(top_srcdir)/TSRM
* Fix extension include path for out of tree builds
* Include config.h with the brackets form
`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.
Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
The libmagic library also uses the HAVE_VISIBILITY macro that should be
defined to 1 if visibility is supported or 0 if not.
Follow-up of GH-5526 (-Wundef)
This fixes few more -Wundef warnings in ext/fileinfo. The
PHP_FILEINFO_UNCOMPRESS seems to be present to be defined at some point
but is currently unused in all build systems. Leaving this intact for
now.
Follow up of GH-5526 (-Wundef)
This test performs a few checks to ensure that "not too much" memory
is used while fileinfo is detecting encodings. It is however platform
specific, and memory usage varies across hosts and as libmagic changes.
Recently a Gentoo user reported a failure in this test at,
https://bugs.gentoo.org/927461
on a big-endian PPC64 machine with output,
---- EXPECTED OUTPUT
131072 => ok
262144 => ok
524288 => ok
1048576 => ok
2097152 => ok
4194304 => ok
8388608 => ok
16777216 => ok
---- ACTUAL OUTPUT
131072 => 10092544
262144 => 10092544
524288 => 12189696
1048576 => 12189696
2097152 => 14352384
4194304 => 18612224
8388608 => 24903680
16777216 => 37486592
---- FAILED
Those numbers are with 8.3.4 and therefore missing commit b7c5813c
which also raises the limits. Checking the "actual" numbers above
against the current values, we see that the limit for 524288 would
need to be bumped to 12189696 to allow this test to pass. Since that
seems reasonable, that's what this commit does.
Closes GH-13795
Closes GH-13940
Make data_file.c's generator output its array initialization
"by list of strings", instead of "by list of chars": that makes the compiler
happier.
Use strtr() with a precomputed map, instead of a loop over ord(),
to generate in 1/100th the time.
Avoids ambiguous 0x tokens (as specified in C standards), by using octal.
Closes GH-10422.
The non-standard major(), minor(), and makedev() can be defined as
macros. These are usually used together with the Autoconf macro
AC_HEADER_MAJOR, which defines the MAJOR_IN_MKDEV if sys/mkdev.h is
available, or MAJOR_IN_SYSMACROS if sys/sysmacros.h is available.
On Solaris/illumos they are in the sys/mkdev.h header (macro defined to
libc implementation) and in sys/sysmacros.h (macro defined with binary
operators and bits shifting). On systems with musl and glibc 2.28 or
later they are defined in sys/sysmacros.h, in glibc 2.27 and earlier
they were in sys/types.h. On BSD-based systems and macOS they are in the
sys/types.h.
Autoconf 2.70 has fixed the AC_HEADER_MAJOR macro, so it detects the
headers properly due to glibc 2.25 throwing deprecation warnings when
using the macros from sys/types.h. With Autoconf 2.69 and earlier the
ac_cv_header_sys_types_h_makedev cache variable can skip the
improper sys/types.h check in the macro.
This change syncs the usage within the ext/fileinfo/libmagic bundled
library and ext/posix.
When sys/mkdev.h header is available, code includes that, otherwise
it conditionally includes the sys/sysmacros.h. The ext/posix has
additional check whether linker sees the makedev, otherwise it checks
if makedev is declared within the given set of headers accoring to the
AC_HEADER_MAJOR logic. Previously the AC_CHECK_FUNCS didn't detect it.
* Update libmagic to 5.45
This also cleans up magicdata.patch: changes that are already in upstream file
were removed from that patch file.
There are five (expected) test output changes.
All these were also checked with the file command.
- bug77961.phpt changes because there's now an early error-return in the
`if (ts == FILE_BADSIZE) {` branch.
- cve-2014-1943.phpt and cve-2014-1943-mb.phpt change because now the crafted
data is recognised as a simh file.
- bug71434.phpt now properly recognises it as a Python file.
- ext/fileinfo/tests/finfo_file_basic.phpt more specific mime type.
* Adjust memory requirement for s390x fileinfo run
The larger database causes a higher memory usage.
Similar to 962c082a5b.
* [ci skip] NEWS
The strcasestr is not present on Windows and on Solaris 10 until Solaris
11 implementation in string.h.
At this point strcasestr is not used in the bundled libmagic (file)
library due to patch removing the strcasestr usage in file.c, however
future libmagic version bump might need it again. This simplifies the
strcasestr check if available on the system without running the test
code and avoiding the unknown issue when cross-compiling. If found, the
HAVE_STRCASESTR is defined, otherwise the strcasestr.c is added to the
build sources.
clang 18 is going to be released and in the meantime the counted_by
attribute usage had been constrained to true flexible arrays,
typical cases such as type name[1] ZEND_ELEMENT_COUNT(size) no longer
build.
* 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
On some configurations, the COMPILE_DL_FILEINFO must come from the
config.h file. If the COMPILE_DL_FILEINFO macro is not set, the build
won't include the ZEND_GET_MODULE block necessary for building this
extension as a shared object.
Closes GH-11505.