1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

414 Commits

Author SHA1 Message Date
Peter Kokot
1cf63a9380 ext/fileinfo: Remove duplicate HAVE_STDINT_H definition (#20392) 2025-11-05 00:36:24 +01:00
Niels Dossche
399cb4ca85 Fix misplaced endif in apprentice_sort() (#18686) 2025-05-29 12:04:07 +02:00
Niels Dossche
37dbad8fcd Upgrade to file 5.46 2025-02-15 12:53:07 +01: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
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
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
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
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
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
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
Ilija Tovilo
9d5f2f1343 Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +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
Anatol Belski
1b39d4c6d2 libmagic: Further simplify diff
Avoid displaced lines where not necessary, use include guard and don't
change called function names.

Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 20:48:35 +02:00
Anatol Belski
5c9cb24aa0 libmagic: Follow up fixes for 5.43
Fixes possible build and runtime issues on Windows.`

Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 16:11:50 +02:00
Anatol Belski
25bb817804 fileinfo: libmagic: Simplify libmagic patch
For the time being, the new args passing pre-compiled regex are cut out.
On the PHP side, PCRE patterns are cached and thus a duplicated
mechanism isn't necessary.

There might be still advantages to carry pre-compiled patterns for
libmagic separately, but reusing this mechanism needs a better
consideration, as it might require to retain from the PHP internal pattern
caching mechanism.

Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 03:02:47 +02:00
Anatol Belski
a3dd514d4d fileinfo: Introduce php_libmagic.* to simplify patch
Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 03:02:47 +02:00
Anatol Belski
a24727a5ca fileinfo: libmagic: Apply libmagic.patch
Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 03:02:46 +02:00
Anatol Belski
6219d7fbc6 fileinfo: libmagic: Check in unpatched 5.43
Signed-off-by: Anatol Belski <ab@php.net>
2022-10-02 03:02:46 +02:00
Stanislav Malyshev
b2f692a9f8 Merge branch 'PHP-8.1' 2022-07-05 00:59:43 -06:00
Christoph M. Becker
ca6d511fa5 Fix #81723: Memory corruption in finfo_buffer()
We need to use the same memory allocator throughout.
2022-07-05 00:44:00 -06:00
George Peter Banyard
d08451b2ca Replace php_stdint.h header with standard headers (#8613) 2022-05-29 11:20:56 +01:00
David Carlier
45e623da26 libmagic: use php_memnstr instead of memmem
Closes GH-8391.
2022-05-23 10:57:44 +02:00
George Peter Banyard
2ecd46f48f Initialise zend_stat_t to fix MSAN build 2022-05-22 16:06:27 +01:00
Anatol Belski
9b78000432 Revert "fileinfo: Obey POSIX in pattern conversion"
This reverts commit 343d1c2b1f.

Also remove the incompatible test data for time being. The new line
handling will need an extra fix.

Signed-off-by: Anatol Belski <ab@php.net>
2021-04-24 14:59:53 +02:00
Anatol Belski
343d1c2b1f fileinfo: Obey POSIX in pattern conversion
Signed-off-by: Anatol Belski <ab@php.net>
2021-04-24 01:40:15 +02:00
Anatol Belski
ecfb888354 fileinfo: Turn back the WS check mitigation
Looks like there's still a timing issue shown on some pipeline runs.

Signed-off-by: Anatol Belski <ab@php.net>
2021-04-06 12:29:04 +02:00
Anatol Belski
f60dc3bd34 fileinfo: More VS compat
Signed-off-by: Anatol Belski <ab@php.net>
2021-04-05 21:23:26 +02:00
Anatol Belski
cd238bd09d fileinfo: Fix VS compat
Signed-off-by: Anatol Belski <ab@php.net>
2021-04-05 21:10:20 +02:00
Anatol Belski
f7ab54cbe7 fileinfo: Restore config.h for libmagic
Signed-off-by: Anatol Belski <ab@php.net>
2021-04-05 20:56:41 +02:00
Anatol Belski
3b9173dc8f fileinfo: Port libmagic 5.40
Signed-off-by: Anatol Belski <ab@php.net>
2021-04-05 20:19:07 +02:00
Christoph M. Becker
e589609b4c Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #77961: finfo_open crafted magic parsing SIGABRT
2020-11-24 14:06:53 +01:00
Christoph M. Becker
39f95f5614 Fix #77961: finfo_open crafted magic parsing SIGABRT
libmagic may abort the running process, which is not desirable for PHP;
we raise a fatal error instead.

Closes GH-6437.
2020-11-24 14:01:15 +01:00
Anatol Belski
f2b40775af Revert "libmagic: Move the allocation on the stack"
This reverts commit 1d84a58736.

Signed-off-by: Anatol Belski <ab@php.net>
2020-09-02 20:04:00 +02:00
Anatol Belski
8c31001bf1 libmagic: Constify arg 2020-09-02 17:35:51 +02:00
Anatol Belski
1d84a58736 libmagic: Move the allocation on the stack 2020-09-02 17:35:51 +02:00
Anatol Belski
c676e8f356 libmagic: Fix VS compat 2020-08-29 19:58:26 +02:00
Anatol Belski
f8f288145b libmagic: Remove unneeded includes
Signed-off-by: Anatol Belski <ab@php.net>
2020-08-29 19:41:53 +02:00
Anatol Belski
bf93f1d824 fileinfo: Followup fixes
Signed-off-by: Anatol Belski <ab@php.net>
2020-08-29 19:03:41 +02:00
Anatol Belski
c3eeab01ba fileinfo: Upgrade to libmagic 5.39
Signed-off-by: Anatol Belski <ab@php.net>
2020-08-29 02:05:56 +02:00
George Peter Banyard
1b2ec73c1d Drop various unused macros/APIs
Also convert_libmagic_pattern() to return a zend_string*

Closes GH-6029
2020-08-26 12:59:43 +02:00
David Carlier
f32653accc fileinfo build fix proposal for haiku.
Haiku already defines a unichar type and different than the fileinfo's anyway.

Closed GH-5983
2020-08-21 16:13:09 +02:00
George Peter Banyard
3f286fa89a Promote Notice to Warning in libmagic
The current behaviour makes little to no sense, having a notice which starts with 'Warning:' should just be a warning

Closes GH-5824
2020-07-10 14:43:43 +02:00
George Peter Banyard
f91f72607b Drop unnecessary stdint and inttypes header checks
These are always available as of C99.

Closes GH-5323

Co-authored-by: "Christoph M. Becker" <cmbecker69@gmx.de>
2020-04-22 20:18:19 +02:00
George Peter Banyard
457380cae7 Drop wchar header check as always defined since C95 2020-03-31 00:14:56 +02:00
Christoph M. Becker
7702b693b5 Fix #79283: Segfault in libmagic patch contains a buffer overflow
To solve this, we properly calculate the required string length upfront
instead of allocating an oversized string (`len * 4 + 4`).
2020-03-16 22:42:15 -07:00