Commit Graph

905 Commits

Author SHA1 Message Date
Hans Krentel (hakre)
329890c149
Fail early in *nix build script
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.
2024-11-09 14:09:58 +01:00
Daniel Scherzer
29f9f903b1
backporting GH-15755 fix. 2024-09-05 02:02:36 +01:00
David Carlier
1e62d203a6
Merge branch 'PHP-8.3' 2024-09-05 01:55:58 +01:00
David Carlier
ea83eba590
Merge branch 'PHP-8.2' into PHP-8.3 2024-09-05 01:41:55 +01:00
Daniel Scherzer
c5e0a6aaab
Fix GH-15752: finfo_file() - parameter validation error messages
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
2024-09-05 01:41:15 +01:00
Máté Kocsis
8d12f666ae
Fix registration of internal readonly child classes (#15459)
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.
2024-08-24 12:36:54 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
e7c4d54d65 Use new helper function for "cannot be empty" ValueErrors 2024-08-21 21:12:17 +01:00
Peter Kokot
634708a14f
Add pcre as a configure step dependency to fileinfo (#15349)
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.
2024-08-12 00:17:29 +02:00
Peter Kokot
ce8ffedccf
Autotools: Normalize ext/fileinfo sources (#15082) 2024-07-24 19:55:37 +02:00
Peter Kokot
97afc86437
Autotools: Quote M4 arguments (#15045)
- AC_MSG_CHECKING
- AC_MSG_RESULT
- AC_MSG_WARN
- AC_MSG_ERROR
- AC_MSG_NOTICE
2024-07-21 01:52:17 +02:00
Niels Dossche
b2c3f2fead
Delete bug78987.phpt test (#14982)
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.
2024-07-17 12:59:17 +02:00
Peter Kokot
0e2e8e0f13
Autotools: Quote all PHP_ADD_BUILD_DIR arguments (#14947)
- All arguments quoted for consistency
- m4_normalize used where list of directories becomes a bit simpler to
  read and see the diff
2024-07-14 16:58:43 +02:00
Peter Kokot
31a21bb0a1
Make ext/fileinfo/generate_patch.sh simpler to use (#14941)
- 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
2024-07-13 22:38:43 +02:00
Christoph M. Becker
32bf50a1d8
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14888: README.REDIST.BINS refers to non-existing LICENSE [ci skip]
2024-07-11 16:40:39 +02:00
Christoph M. Becker
a23775a30d
Fix GH-14888: README.REDIST.BINS refers to non-existing LICENSE [ci skip]
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.
2024-07-11 16:39:22 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* 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.
2024-06-26 00:26:43 +02:00
Peter Kokot
6e2ad3c4ba
Define HAVE_VISIBILITY for fileinfo extension (#14618)
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)
2024-06-21 16:18:28 +02:00
Peter Kokot
845af7778e
Remove redundant win32/unistd.h includes (#14533)
At this point win32/unistd.h only declares usleep which isn't used at
these places.
2024-06-11 09:47:23 +02:00
Peter Kokot
d3901b8ca6
Sync PHP_FILEINFO_UNCOMPRESS #if/ifdef/defined (#14525)
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)
2024-06-10 08:11:25 +02:00
Gina Peter Banyard
b8aa227016 ext/fileinfo: Fix [-Wsign-compare] warnings 2024-06-06 16:18:23 +01:00
Gina Peter Banyard
25a5146180
Clean-up unused headers (#14365)
* ext/mbstring.c: clean-up headers and include intrinsics
2024-06-01 17:12:42 +01:00
Peter Kokot
1d0cdd1b41
Remove unused ext/fileinfo/libmagic/elfclass.h file (#14344)
Usage was removed via 919abf0cb1 due to
redundand code in php-src. This also updates the appended libmagic patch
file.
2024-05-28 21:43:38 +02:00
Niels Dossche
bc62b41126
Merge branch 'PHP-8.3'
* PHP-8.3:
  ext/fileinfo/tests/bug78987.phpt: increase a memory limit
2024-04-11 15:58:25 +02:00
Michael Orlitzky
4ded247675
ext/fileinfo/tests/bug78987.phpt: increase a memory limit
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
2024-04-11 15:58:06 +02:00
Juan Morales
186465b1dd
QA - finfo_open - increase test coverage (#13839) 2024-03-30 15:16:06 +01:00
Guillaume Outters
bcd3eec44a Fix bug #65106: PHP fails to compile ext/fileinfo
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.
2024-03-22 15:00:15 +01:00
Máté Kocsis
b06c95b631
Declare the missing true return types (#13709) 2024-03-16 07:26:37 +01:00
Peter Kokot
c6f4c26e1b
Check major, minor and makedev with Autoconf's AC_HEADER_MAJOR (#13706)
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.
2024-03-15 21:18:05 +01:00
Máté Kocsis
f2e199e878
Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Máté Kocsis
10957e498c
Do not generate frameless info items when func info generation is disabled
While here, I fixed newlines around arginfo and function entry generation. Previously, newlines were repeated.
2024-02-18 11:39:00 +01:00
Niels Dossche
87abd500e3
Fix 32-bit fileinfo (#13404)
libmagic 5.45 has a regression on 32-bit that is fixed in current HEAD,
but that's not released yet. Pull in the upstream fix [1].

[1] 218fdf813f
2024-02-15 20:47:49 +01:00
Niels Dossche
be34b96975 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13344: finfo::buffer(): Failed identify data 0:(null)
2024-02-13 21:21:07 +01:00
Niels Dossche
e71b597f4d Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13344: finfo::buffer(): Failed identify data 0:(null)
2024-02-13 21:15:37 +01:00
Niels Dossche
c2b671cb1b Fix GH-13344: finfo::buffer(): Failed identify data 0:(null)
Credits to ranvis for finding the upstream commit that fixes the issue.

This backports 029b82459e

Closes GH-13370.
2024-02-13 21:13:43 +01:00
Niels Dossche
b7c5813c98
Update libmagic to 5.45 (#13369)
* 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
2024-02-13 21:11:57 +01:00
Peter Kokot
801787d51d
Simplify strcasestr check in fileinfo (#13365)
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.
2024-02-10 15:11:48 +01:00
David CARLIER
b8f10decb3
ZEND_ELEMENT_COUNT usage reduction. (#13324)
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.
2024-02-04 19:09:15 +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
David CARLIER
cc2bf11951
zend: introducing ZEND_ELEMENT_COUNT for struct's dynamic arrays. (#12650)
zend: introducing ZEND_ELEMENT_COUNT for struct's dynamic and flexible arrays.

It is mostly for ubsan and helping array bound checking.
2023-11-13 12:42:45 +00:00
Anatol Belski
bd24c56207 fileinfo: Backport svg detection patch
This patch is a port of 1f5bea34 and adds a port for 5.43 based
branches. The related test is unchanged.

Signed-off-by: Anatol Belski <ab@php.net>
2023-09-30 18:22:14 +02:00
Anatol Belski
4b22cb213a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  fileinfo: Backport svg detection patch
2023-09-30 16:26:24 +02:00
usarise
1f5bea3452 fileinfo: Backport svg detection patch 2023-09-30 16:17:03 +02:00
Anatol Belski
292e10b14b
fileinfo: Add test for xz type
Ref: #11298

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:37:53 +02:00
Anatol Belski
97f0d97d2a fileinfo: Backport xz detection patch
Upstream: 9b0459afab

Fixes: #11298

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:02:46 +02:00
Anatol Belski
86f79b299e
fileinfo: Backport xz detection fix
Upstream: 9b0459afab

Fixes: #11298

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 17:58:38 +02:00
Niels Dossche
b0ba368d53 Fix GH-11408: Unable to build PHP 8.3.0 alpha 1 / fileinfo extension
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.
2023-06-23 17:43:52 +02:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Anatol Belski
3c602fdf67 libmagic: Keep the WS limitation piece
Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 21:00:03 +02:00