diff --git a/ext/fileinfo/config.m4 b/ext/fileinfo/config.m4 index 346061411e086..e2c17f7f1f849 100644 --- a/ext/fileinfo/config.m4 +++ b/ext/fileinfo/config.m4 @@ -29,17 +29,12 @@ if test "$PHP_FILEINFO" != "no"; then AC_CHECK_HEADERS([sys/sysmacros.h]) - AC_CHECK_FUNCS([strcasestr],,[ - AC_MSG_NOTICE([using libmagic strcasestr implementation]) - libmagic_sources="$libmagic_sources libmagic/strcasestr.c" - ]) - AX_GCC_FUNC_ATTRIBUTE([visibility]) PHP_NEW_EXTENSION([fileinfo], [fileinfo.c php_libmagic.c $libmagic_sources], [$ext_shared],, - [-I@ext_srcdir@/libmagic]) + [-I@ext_srcdir@/libmagic -DHAVE_STRCASESTR=1]) PHP_ADD_BUILD_DIR([$ext_builddir/libmagic]) PHP_ADD_EXTENSION_DEP(fileinfo, pcre) diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 50695981796e8..da02e8f113a38 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -56,7 +56,7 @@ static void finfo_objects_free(zend_object *object) { finfo_object *intern = php_finfo_fetch_object(object); - magic_close(intern->magic); + php_magic_close(intern->magic); zend_object_std_dtor(&intern->zo); } /* }}} */ @@ -118,7 +118,7 @@ PHP_MINFO_FUNCTION(fileinfo) { char magic_ver[15]; - int raw_version = magic_version(); + int raw_version = php_magic_version(); (void)snprintf(magic_ver, sizeof(magic_ver), "%d.%d", raw_version / 100, raw_version % 100); php_info_print_table_start(); @@ -145,7 +145,7 @@ PHP_FUNCTION(finfo_open) if (object) { zend_replace_error_handling(EH_THROW, NULL, &zeh); - magic_close(Z_FINFO_P(object)->magic); + php_magic_close(Z_FINFO_P(object)->magic); Z_FINFO_P(object)->magic = NULL; } @@ -162,16 +162,16 @@ PHP_FUNCTION(finfo_open) file = resolved_path; } - struct magic_set *magic = magic_open(options); + struct magic_set *magic = php_magic_open(options); if (magic == NULL) { php_error_docref(NULL, E_WARNING, "Invalid mode '" ZEND_LONG_FMT "'.", options); goto err; } - if (magic_load(magic, file) == -1) { + if (php_magic_load(magic, file) == -1) { php_error_docref(NULL, E_WARNING, "Failed to load magic database at \"%s\"", file); - magic_close(magic); + php_magic_close(magic); goto err; } @@ -228,7 +228,7 @@ PHP_FUNCTION(finfo_set_flags) /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */ - magic_setflags(Z_FINFO_P(self)->magic, options); + php_magic_setflags(Z_FINFO_P(self)->magic, options); RETURN_TRUE; } @@ -271,9 +271,9 @@ static const char* php_fileinfo_from_path(struct magic_set *magic, const zend_st } } if (!ret_val) { - ret_val = magic_stream(magic, stream); + ret_val = php_magic_stream(magic, stream); if (UNEXPECTED(ret_val == NULL)) { - php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); + php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic)); } } @@ -311,18 +311,18 @@ PHP_FUNCTION(finfo_file) } /* Set options for the current file/buffer. */ - int old_options = magic_getflags(magic); + int old_options = php_magic_getflags(magic); if (options) { /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */ - magic_setflags(magic, options); + php_magic_setflags(magic, options); } const char *ret_val = php_fileinfo_from_path(magic, path, context); /* Restore options */ if (options) { - magic_setflags(magic, old_options); + php_magic_setflags(magic, old_options); } if (UNEXPECTED(ret_val == NULL)) { @@ -359,22 +359,22 @@ PHP_FUNCTION(finfo_buffer) struct magic_set *magic = Z_FINFO_P(self)->magic; /* Set options for the current file/buffer. */ - int old_options = magic_getflags(magic); + int old_options = php_magic_getflags(magic); if (options) { /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */ - magic_setflags(magic, options); + php_magic_setflags(magic, options); } - const char *ret_val = magic_buffer(magic, ZSTR_VAL(buffer), ZSTR_LEN(buffer)); + const char *ret_val = php_magic_buffer(magic, ZSTR_VAL(buffer), ZSTR_LEN(buffer)); /* Restore options */ if (options) { - magic_setflags(magic, old_options); + php_magic_setflags(magic, old_options); } if (UNEXPECTED(ret_val == NULL)) { - php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); + php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic)); RETURN_FALSE; } else { RETURN_STRING(ret_val); @@ -415,15 +415,15 @@ PHP_FUNCTION(mime_content_type) RETURN_THROWS(); } - magic = magic_open(MAGIC_MIME_TYPE); + magic = php_magic_open(MAGIC_MIME_TYPE); if (UNEXPECTED(magic == NULL)) { php_error_docref(NULL, E_WARNING, "Failed to load magic database"); RETURN_FALSE; } - if (UNEXPECTED(magic_load(magic, NULL) == -1)) { - php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); - magic_close(magic); + if (UNEXPECTED(php_magic_load(magic, NULL) == -1)) { + php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic)); + php_magic_close(magic); RETURN_FALSE; } @@ -436,9 +436,9 @@ PHP_FUNCTION(mime_content_type) zend_off_t current_stream_pos = php_stream_tell(stream); php_stream_seek(stream, 0, SEEK_SET); - ret_val = magic_stream(magic, stream); + ret_val = php_magic_stream(magic, stream); if (UNEXPECTED(ret_val == NULL)) { - php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); + php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", php_magic_errno(magic), php_magic_error(magic)); } php_stream_seek(stream, current_stream_pos, SEEK_SET); @@ -449,5 +449,5 @@ PHP_FUNCTION(mime_content_type) } else { RETVAL_STRING(ret_val); } - magic_close(magic); + php_magic_close(magic); } diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch index 4eb7ccd336f89..7457b0316656c 100644 --- a/ext/fileinfo/libmagic.patch +++ b/ext/fileinfo/libmagic.patch @@ -1,6 +1,6 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c ---- libmagic.orig/apprentice.c 2024-11-27 16:37:00.000000000 +0100 -+++ libmagic/apprentice.c 2025-02-09 02:25:02.364884555 +0100 +--- libmagic.orig/apprentice.c 2024-11-27 10:37:00.000000000 -0500 ++++ libmagic/apprentice.c 2026-03-19 16:25:43.010672679 -0400 @@ -32,7 +32,7 @@ #include "file.h" @@ -40,6 +40,25 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c #ifdef COMPILE_ONLY int main(int, char *[]); +@@ -206,14 +207,14 @@ + return 1; + } + +- if ((ms = magic_open(MAGIC_CHECK)) == NULL) { ++ if ((ms = php_magic_open(MAGIC_CHECK)) == NULL) { + (void)fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + return 1; + } +- ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; ++ ret = php_magic_compile(ms, argv[1]) == -1 ? 1 : 0; + if (ret == 1) +- (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); +- magic_close(ms); ++ (void)fprintf(stderr, "%s: %s\n", progname, php_magic_error(ms)); ++ php_magic_close(ms); + return ret; + } + #endif /* COMPILE_ONLY */ @@ -341,7 +342,11 @@ { int type; @@ -96,7 +115,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } file_protected struct magic_set * -@@ -553,7 +549,7 @@ +@@ -553,11 +549,11 @@ struct magic_set *ms; size_t i, len; @@ -105,6 +124,11 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c sizeof(*ms)))) == NULL) return NULL; +- if (magic_setflags(ms, flags) == -1) { ++ if (php_magic_setflags(ms, flags) == -1) { + errno = EINVAL; + goto free; + } @@ -566,14 +562,13 @@ ms->o.blen = 0; len = (ms->c.len = 10) * sizeof(*ms->c.li); @@ -268,9 +292,10 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c (void)file_reset(ms, 0); +- if ((fn = magic_getpath(fn, action)) == NULL) + /* XXX disabling default magic loading so the compiled in data is used */ +#if 0 - if ((fn = magic_getpath(fn, action)) == NULL) ++ if ((fn = php_magic_getpath(fn, action)) == NULL) return -1; +#endif @@ -325,14 +350,14 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c // Don't warn for DER if (mpa.type == FILE_DER) return 0; -@@ -1151,6 +1075,7 @@ +@@ -1150,6 +1074,7 @@ + ma->mp->desc); file_mdump(ma->mp); file_mdump(mb->mp); +#endif return 0; } return x > 0 ? -1 : 1; - } @@ -1303,7 +1228,7 @@ size_t incr = mset[i].max + ALLOC_INCR; @@ -954,8 +979,8 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c if (ma[j].cont_level == 0) break; diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c ---- libmagic.orig/ascmagic.c 2024-06-19 18:18:53.000000000 +0200 -+++ libmagic/ascmagic.c 2025-02-09 01:20:19.757840211 +0100 +--- libmagic.orig/ascmagic.c 2024-06-19 12:18:53.000000000 -0400 ++++ libmagic/ascmagic.c 2026-03-19 16:25:42.998672674 -0400 @@ -96,7 +96,7 @@ rv = file_ascmagic_with_encoding(ms, &bb, ubuf, ulen, code, type, text); @@ -996,8 +1021,8 @@ diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c return rv; } diff -u libmagic.orig/buffer.c libmagic/buffer.c ---- libmagic.orig/buffer.c 2024-06-19 18:18:53.000000000 +0200 -+++ libmagic/buffer.c 2025-02-09 01:20:19.757910844 +0100 +--- libmagic.orig/buffer.c 2024-06-19 12:18:53.000000000 -0400 ++++ libmagic/buffer.c 2026-03-19 16:25:42.998672674 -0400 @@ -31,19 +31,21 @@ #endif /* lint */ @@ -1055,8 +1080,8 @@ diff -u libmagic.orig/buffer.c libmagic/buffer.c goto out; } diff -u libmagic.orig/cdf.c libmagic/cdf.c ---- libmagic.orig/cdf.c 2024-11-25 22:24:59.000000000 +0100 -+++ libmagic/cdf.c 2025-02-09 01:25:00.187641434 +0100 +--- libmagic.orig/cdf.c 2024-11-25 16:24:59.000000000 -0500 ++++ libmagic/cdf.c 2026-03-19 16:25:42.998672674 -0400 @@ -43,7 +43,9 @@ #include #endif @@ -1286,8 +1311,8 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c #endif diff -u libmagic.orig/cdf.h libmagic/cdf.h ---- libmagic.orig/cdf.h 2024-11-25 22:18:55.000000000 +0100 -+++ libmagic/cdf.h 2025-02-09 01:23:35.871635744 +0100 +--- libmagic.orig/cdf.h 2024-11-25 16:18:55.000000000 -0500 ++++ libmagic/cdf.h 2026-03-19 16:25:42.990672671 -0400 @@ -37,8 +37,6 @@ #ifdef WIN32 @@ -1439,8 +1464,8 @@ diff -u libmagic.orig/cdf.h libmagic/cdf.h diff -u libmagic.orig/compress.c libmagic/compress.c ---- libmagic.orig/compress.c 2024-11-10 17:52:27.000000000 +0100 -+++ libmagic/compress.c 2025-02-09 01:59:42.978538071 +0100 +--- libmagic.orig/compress.c 2024-11-10 11:52:27.000000000 -0500 ++++ libmagic/compress.c 2026-03-19 16:25:42.994672673 -0400 @@ -64,13 +64,14 @@ #if defined(HAVE_SYS_TIME_H) #include @@ -1660,14 +1685,25 @@ diff -u libmagic.orig/compress.c libmagic/compress.c if (*newch == NULL) return makeerror(newch, n, "No buffer, %s", strerror(errno)); +@@ -1156,8 +1087,8 @@ + fdp[i][0] = fdp[i][1] = -1; + + /* +- * There are multithreaded users who run magic_file() +- * from dozens of threads. If two parallel magic_file() calls ++ * There are multithreaded users who run php_magic_file() ++ * from dozens of threads. If two parallel php_magic_file() calls + * analyze two large compressed files, both will spawn + * an uncompressing child here, which writes out uncompressed data. + * We read some portion, then close the pipe, then waitpid() the child. @@ -1300,3 +1231,4 @@ return rv; } #endif +#endif diff -u libmagic.orig/der.c libmagic/der.c ---- libmagic.orig/der.c 2024-11-25 23:31:53.000000000 +0100 -+++ libmagic/der.c 2025-02-09 01:20:19.770853011 +0100 +--- libmagic.orig/der.c 2024-11-25 17:31:53.000000000 -0500 ++++ libmagic/der.c 2026-03-19 16:25:43.002672676 -0400 @@ -54,7 +54,9 @@ #include "magic.h" #include "der.h" @@ -1679,8 +1715,8 @@ diff -u libmagic.orig/der.c libmagic/der.c #include #endif diff -u libmagic.orig/der.h libmagic/der.h ---- libmagic.orig/der.h 2024-11-25 22:26:18.000000000 +0100 -+++ libmagic/der.h 2023-04-09 22:21:58.195018580 +0200 +--- libmagic.orig/der.h 2024-11-25 16:26:18.000000000 -0500 ++++ libmagic/der.h 2026-03-19 16:25:43.006672678 -0400 @@ -24,5 +24,5 @@ * POSSIBILITY OF SUCH DAMAGE. */ @@ -1690,8 +1726,8 @@ diff -u libmagic.orig/der.h libmagic/der.h +extern int der_offs(struct magic_set *, struct magic *, size_t); +extern int der_cmp(struct magic_set *, struct magic *); diff -u libmagic.orig/encoding.c libmagic/encoding.c ---- libmagic.orig/encoding.c 2024-10-29 21:56:48.000000000 +0100 -+++ libmagic/encoding.c 2025-02-09 01:20:19.770879123 +0100 +--- libmagic.orig/encoding.c 2024-10-29 16:56:48.000000000 -0400 ++++ libmagic/encoding.c 2026-03-19 16:25:43.010672679 -0400 @@ -97,7 +97,7 @@ nbytes = ms->encoding_max; @@ -1726,8 +1762,8 @@ diff -u libmagic.orig/encoding.c libmagic/encoding.c return rv; } diff -u libmagic.orig/file.h libmagic/file.h ---- libmagic.orig/file.h 2024-11-27 16:37:00.000000000 +0100 -+++ libmagic/file.h 2025-02-09 01:47:36.242811911 +0100 +--- libmagic.orig/file.h 2024-11-27 10:37:00.000000000 -0500 ++++ libmagic/file.h 2026-03-19 16:25:42.986672670 -0400 @@ -27,15 +27,13 @@ */ /* @@ -1936,8 +1972,8 @@ diff -u libmagic.orig/file.h libmagic/file.h #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK) #define QUICK diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c ---- libmagic.orig/fsmagic.c 2024-06-19 18:18:53.000000000 +0200 -+++ libmagic/fsmagic.c 2025-02-09 01:20:19.770987982 +0100 +--- libmagic.orig/fsmagic.c 2024-06-19 12:18:53.000000000 -0400 ++++ libmagic/fsmagic.c 2026-03-19 16:25:43.006672678 -0400 @@ -66,26 +66,10 @@ # define minor(dev) ((dev) & 0xff) #endif @@ -2229,8 +2265,8 @@ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c #ifndef __COHERENT__ case S_IFSOCK: diff -u libmagic.orig/funcs.c libmagic/funcs.c ---- libmagic.orig/funcs.c 2024-06-19 18:18:53.000000000 +0200 -+++ libmagic/funcs.c 2025-02-09 01:29:25.403659334 +0100 +--- libmagic.orig/funcs.c 2024-06-19 12:18:53.000000000 -0400 ++++ libmagic/funcs.c 2026-03-19 16:25:42.990672671 -0400 @@ -66,7 +66,7 @@ file_private void file_clearbuf(struct magic_set *ms) @@ -2592,8 +2628,8 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c file_protected int file_clear_closexec(int fd) { diff -u libmagic.orig/magic.c libmagic/magic.c ---- libmagic.orig/magic.c 2024-06-19 18:18:53.000000000 +0200 -+++ libmagic/magic.c 2025-02-09 01:20:19.771155033 +0100 +--- libmagic.orig/magic.c 2024-06-19 12:18:53.000000000 -0400 ++++ libmagic/magic.c 2026-03-19 16:25:42.994672673 -0400 @@ -25,11 +25,6 @@ * SUCH DAMAGE. */ @@ -2616,7 +2652,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c #include #ifdef QUICK #include -@@ -69,200 +66,18 @@ +@@ -69,202 +66,20 @@ #endif #endif @@ -2821,9 +2857,29 @@ diff -u libmagic.orig/magic.c libmagic/magic.c -} - file_public struct magic_set * - magic_open(int flags) +-magic_open(int flags) ++php_magic_open(int flags) + { + return file_ms_alloc(flags); + } +@@ -303,7 +118,7 @@ + } + + file_public void +-magic_close(struct magic_set *ms) ++php_magic_close(struct magic_set *ms) { -@@ -321,21 +136,6 @@ + if (ms == NULL) + return; +@@ -314,30 +129,15 @@ + * load a magic file + */ + file_public int +-magic_load(struct magic_set *ms, const char *magicfile) ++php_magic_load(struct magic_set *ms, const char *magicfile) + { + if (ms == NULL) + return -1; return file_apprentice(ms, magicfile, FILE_LOAD); } @@ -2831,7 +2887,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c -/* - * Install a set of compiled magic buffers. - */ --file_public int + file_public int -magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes, - size_t nbufs) -{ @@ -2842,10 +2898,30 @@ diff -u libmagic.orig/magic.c libmagic/magic.c -} -#endif - +-file_public int +-magic_compile(struct magic_set *ms, const char *magicfile) ++php_magic_compile(struct magic_set *ms, const char *magicfile) + { + if (ms == NULL) + return -1; +@@ -345,7 +145,7 @@ + } + file_public int - magic_compile(struct magic_set *ms, const char *magicfile) +-magic_check(struct magic_set *ms, const char *magicfile) ++php_magic_check(struct magic_set *ms, const char *magicfile) { -@@ -360,39 +160,6 @@ + if (ms == NULL) + return -1; +@@ -353,80 +153,53 @@ + } + + file_public int +-magic_list(struct magic_set *ms, const char *magicfile) ++php_magic_list(struct magic_set *ms, const char *magicfile) + { + if (ms == NULL) + return -1; return file_apprentice(ms, magicfile, FILE_LIST); } @@ -2885,7 +2961,11 @@ diff -u libmagic.orig/magic.c libmagic/magic.c #ifndef COMPILE_ONLY /* -@@ -403,7 +170,7 @@ + * find type of descriptor + */ + file_public const char * +-magic_descriptor(struct magic_set *ms, int fd) ++php_magic_descriptor(struct magic_set *ms, int fd) { if (ms == NULL) return NULL; @@ -2894,7 +2974,11 @@ diff -u libmagic.orig/magic.c libmagic/magic.c } /* -@@ -414,19 +181,25 @@ + * find type of named file + */ + file_public const char * +-magic_file(struct magic_set *ms, const char *inname) ++php_magic_file(struct magic_set *ms, const char *inname) { if (ms == NULL) return NULL; @@ -2903,7 +2987,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c +} + +file_public const char * -+magic_stream(struct magic_set *ms, php_stream *stream) ++php_magic_stream(struct magic_set *ms, php_stream *stream) +{ + if (ms == NULL) + return NULL; @@ -3056,6 +3140,15 @@ diff -u libmagic.orig/magic.c libmagic/magic.c } out: return rv == 0 ? file_getbuffer(ms) : NULL; +@@ -546,7 +269,7 @@ + + + file_public const char * +-magic_buffer(struct magic_set *ms, const void *buf, size_t nb) ++php_magic_buffer(struct magic_set *ms, const void *buf, size_t nb) + { + if (ms == NULL) + return NULL; @@ -556,7 +279,7 @@ * The main work is done here! * We have the file name and/or the data buffer to be identified. @@ -3065,9 +3158,70 @@ diff -u libmagic.orig/magic.c libmagic/magic.c return NULL; } return file_getbuffer(ms); +@@ -564,7 +287,7 @@ + #endif + + file_public const char * +-magic_error(struct magic_set *ms) ++php_magic_error(struct magic_set *ms) + { + if (ms == NULL) + return "Magic database is not open"; +@@ -572,7 +295,7 @@ + } + + file_public int +-magic_errno(struct magic_set *ms) ++php_magic_errno(struct magic_set *ms) + { + if (ms == NULL) + return EINVAL; +@@ -580,7 +303,7 @@ + } + + file_public int +-magic_getflags(struct magic_set *ms) ++php_magic_getflags(struct magic_set *ms) + { + if (ms == NULL) + return -1; +@@ -589,7 +312,7 @@ + } + + file_public int +-magic_setflags(struct magic_set *ms, int flags) ++php_magic_setflags(struct magic_set *ms, int flags) + { + if (ms == NULL) + return -1; +@@ -602,13 +325,13 @@ + } + + file_public int +-magic_version(void) ++php_magic_version(void) + { + return MAGIC_VERSION; + } + + file_public int +-magic_setparam(struct magic_set *ms, int param, const void *val) ++php_magic_setparam(struct magic_set *ms, int param, const void *val) + { + if (ms == NULL) + return -1; +@@ -651,7 +374,7 @@ + } + + file_public int +-magic_getparam(struct magic_set *ms, int param, void *val) ++php_magic_getparam(struct magic_set *ms, int param, void *val) + { + if (ms == NULL) + return -1; diff -u libmagic.orig/magic.h libmagic/magic.h ---- libmagic.orig/magic.h 2025-02-09 12:43:22.903059789 +0100 -+++ libmagic/magic.h 2025-02-09 01:39:57.110146603 +0100 +--- libmagic.orig/magic.h 2026-03-19 17:04:43.359619696 -0400 ++++ libmagic/magic.h 2026-03-19 16:35:50.382918451 -0400 @@ -47,8 +47,6 @@ * extensions */ #define MAGIC_COMPRESS_TRANSP 0x2000000 /* Check inside compressed files @@ -3100,17 +3254,67 @@ diff -u libmagic.orig/magic.h libmagic/magic.h b\30extension\0\ b\31transp_compression\0\ " -@@ -130,6 +128,7 @@ - - const char *magic_getpath(const char *, int); - const char *magic_file(magic_t, const char *); -+const char *magic_stream(magic_t, php_stream *); - const char *magic_descriptor(magic_t, int); - const char *magic_buffer(magic_t, const void *, size_t); +@@ -125,26 +123,27 @@ + #endif + typedef struct magic_set *magic_t; +-magic_t magic_open(int); +-void magic_close(magic_t); ++magic_t php_magic_open(int); ++void php_magic_close(magic_t); + +-const char *magic_getpath(const char *, int); +-const char *magic_file(magic_t, const char *); +-const char *magic_descriptor(magic_t, int); +-const char *magic_buffer(magic_t, const void *, size_t); +- +-const char *magic_error(magic_t); +-int magic_getflags(magic_t); +-int magic_setflags(magic_t, int); +- +-int magic_version(void); +-int magic_load(magic_t, const char *); +-int magic_load_buffers(magic_t, void **, size_t *, size_t); +- +-int magic_compile(magic_t, const char *); +-int magic_check(magic_t, const char *); +-int magic_list(magic_t, const char *); +-int magic_errno(magic_t); ++const char *php_magic_getpath(const char *, int); ++const char *php_magic_file(magic_t, const char *); ++const char *php_magic_stream(magic_t, php_stream *); ++const char *php_magic_descriptor(magic_t, int); ++const char *php_magic_buffer(magic_t, const void *, size_t); ++ ++const char *php_magic_error(magic_t); ++int php_magic_getflags(magic_t); ++int php_magic_setflags(magic_t, int); ++ ++int php_magic_version(void); ++int php_magic_load(magic_t, const char *); ++int php_magic_load_buffers(magic_t, void **, size_t *, size_t); ++ ++int php_magic_compile(magic_t, const char *); ++int php_magic_check(magic_t, const char *); ++int php_magic_list(magic_t, const char *); ++int php_magic_errno(magic_t); + + #define MAGIC_PARAM_INDIR_MAX 0 + #define MAGIC_PARAM_NAME_MAX 1 +@@ -157,8 +156,8 @@ + #define MAGIC_PARAM_ELF_SHSIZE_MAX 8 + #define MAGIC_PARAM_MAGWARN_MAX 9 + +-int magic_setparam(magic_t, int, const void *); +-int magic_getparam(magic_t, int, void *); ++int php_magic_setparam(magic_t, int, const void *); ++int php_magic_getparam(magic_t, int, void *); + + #ifdef __cplusplus + }; diff -u libmagic.orig/print.c libmagic/print.c ---- libmagic.orig/print.c 2024-10-06 19:04:42.000000000 +0200 -+++ libmagic/print.c 2025-02-09 01:36:41.713156291 +0100 +--- libmagic.orig/print.c 2024-10-06 13:04:42.000000000 -0400 ++++ libmagic/print.c 2026-03-19 16:25:42.982672668 -0400 @@ -74,7 +74,7 @@ if (m->mask_op & FILE_OPINVERSE) (void) fputc('~', stderr); @@ -3187,8 +3391,8 @@ diff -u libmagic.orig/print.c libmagic/print.c if (pp == NULL) goto out; diff -u libmagic.orig/readcdf.c libmagic/readcdf.c ---- libmagic.orig/readcdf.c 2024-11-25 22:07:46.000000000 +0100 -+++ libmagic/readcdf.c 2025-02-09 01:20:19.771337672 +0100 +--- libmagic.orig/readcdf.c 2024-11-25 16:07:46.000000000 -0500 ++++ libmagic/readcdf.c 2026-03-19 16:25:43.002672676 -0400 @@ -31,7 +31,9 @@ #include @@ -3307,8 +3511,8 @@ diff -u libmagic.orig/readcdf.c libmagic/readcdf.c /* If we handled it already, return */ if (i != -1) diff -u libmagic.orig/softmagic.c libmagic/softmagic.c ---- libmagic.orig/softmagic.c 2024-11-27 16:37:00.000000000 +0100 -+++ libmagic/softmagic.c 2025-02-09 01:21:46.845689318 +0100 +--- libmagic.orig/softmagic.c 2024-11-27 10:37:00.000000000 -0500 ++++ libmagic/softmagic.c 2026-03-19 16:25:42.986672670 -0400 @@ -32,7 +32,7 @@ #include "file.h" diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c index 31d01a2bd8d63..2eb7d92dbdce8 100644 --- a/ext/fileinfo/libmagic/apprentice.c +++ b/ext/fileinfo/libmagic/apprentice.c @@ -207,14 +207,14 @@ main(int argc, char *argv[]) return 1; } - if ((ms = magic_open(MAGIC_CHECK)) == NULL) { + if ((ms = php_magic_open(MAGIC_CHECK)) == NULL) { (void)fprintf(stderr, "%s: %s\n", progname, strerror(errno)); return 1; } - ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; + ret = php_magic_compile(ms, argv[1]) == -1 ? 1 : 0; if (ret == 1) - (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); - magic_close(ms); + (void)fprintf(stderr, "%s: %s\n", progname, php_magic_error(ms)); + php_magic_close(ms); return ret; } #endif /* COMPILE_ONLY */ @@ -553,7 +553,7 @@ file_ms_alloc(int flags) sizeof(*ms)))) == NULL) return NULL; - if (magic_setflags(ms, flags) == -1) { + if (php_magic_setflags(ms, flags) == -1) { errno = EINVAL; goto free; } @@ -667,7 +667,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) /* XXX disabling default magic loading so the compiled in data is used */ #if 0 - if ((fn = magic_getpath(fn, action)) == NULL) + if ((fn = php_magic_getpath(fn, action)) == NULL) return -1; #endif diff --git a/ext/fileinfo/libmagic/compress.c b/ext/fileinfo/libmagic/compress.c index 85f082ed01135..4b1b03c8b55db 100644 --- a/ext/fileinfo/libmagic/compress.c +++ b/ext/fileinfo/libmagic/compress.c @@ -1087,8 +1087,8 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, int nofork, fdp[i][0] = fdp[i][1] = -1; /* - * There are multithreaded users who run magic_file() - * from dozens of threads. If two parallel magic_file() calls + * There are multithreaded users who run php_magic_file() + * from dozens of threads. If two parallel php_magic_file() calls * analyze two large compressed files, both will spawn * an uncompressing child here, which writes out uncompressed data. * We read some portion, then close the pipe, then waitpid() the child. diff --git a/ext/fileinfo/libmagic/magic.c b/ext/fileinfo/libmagic/magic.c index e24f22e50d34b..c85c290c8873e 100644 --- a/ext/fileinfo/libmagic/magic.c +++ b/ext/fileinfo/libmagic/magic.c @@ -79,7 +79,7 @@ file_private const char *file_or_stream(struct magic_set *, const char *, php_st #endif file_public struct magic_set * -magic_open(int flags) +php_magic_open(int flags) { return file_ms_alloc(flags); } @@ -118,7 +118,7 @@ unreadable_info(struct magic_set *ms, mode_t md, const char *file) } file_public void -magic_close(struct magic_set *ms) +php_magic_close(struct magic_set *ms) { if (ms == NULL) return; @@ -129,7 +129,7 @@ magic_close(struct magic_set *ms) * load a magic file */ file_public int -magic_load(struct magic_set *ms, const char *magicfile) +php_magic_load(struct magic_set *ms, const char *magicfile) { if (ms == NULL) return -1; @@ -137,7 +137,7 @@ magic_load(struct magic_set *ms, const char *magicfile) } file_public int -magic_compile(struct magic_set *ms, const char *magicfile) +php_magic_compile(struct magic_set *ms, const char *magicfile) { if (ms == NULL) return -1; @@ -145,7 +145,7 @@ magic_compile(struct magic_set *ms, const char *magicfile) } file_public int -magic_check(struct magic_set *ms, const char *magicfile) +php_magic_check(struct magic_set *ms, const char *magicfile) { if (ms == NULL) return -1; @@ -153,7 +153,7 @@ magic_check(struct magic_set *ms, const char *magicfile) } file_public int -magic_list(struct magic_set *ms, const char *magicfile) +php_magic_list(struct magic_set *ms, const char *magicfile) { if (ms == NULL) return -1; @@ -166,7 +166,7 @@ magic_list(struct magic_set *ms, const char *magicfile) * find type of descriptor */ file_public const char * -magic_descriptor(struct magic_set *ms, int fd) +php_magic_descriptor(struct magic_set *ms, int fd) { if (ms == NULL) return NULL; @@ -177,7 +177,7 @@ magic_descriptor(struct magic_set *ms, int fd) * find type of named file */ file_public const char * -magic_file(struct magic_set *ms, const char *inname) +php_magic_file(struct magic_set *ms, const char *inname) { if (ms == NULL) return NULL; @@ -185,7 +185,7 @@ magic_file(struct magic_set *ms, const char *inname) } file_public const char * -magic_stream(struct magic_set *ms, php_stream *stream) +php_magic_stream(struct magic_set *ms, php_stream *stream) { if (ms == NULL) return NULL; @@ -269,7 +269,7 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream) file_public const char * -magic_buffer(struct magic_set *ms, const void *buf, size_t nb) +php_magic_buffer(struct magic_set *ms, const void *buf, size_t nb) { if (ms == NULL) return NULL; @@ -287,7 +287,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb) #endif file_public const char * -magic_error(struct magic_set *ms) +php_magic_error(struct magic_set *ms) { if (ms == NULL) return "Magic database is not open"; @@ -295,7 +295,7 @@ magic_error(struct magic_set *ms) } file_public int -magic_errno(struct magic_set *ms) +php_magic_errno(struct magic_set *ms) { if (ms == NULL) return EINVAL; @@ -303,7 +303,7 @@ magic_errno(struct magic_set *ms) } file_public int -magic_getflags(struct magic_set *ms) +php_magic_getflags(struct magic_set *ms) { if (ms == NULL) return -1; @@ -312,7 +312,7 @@ magic_getflags(struct magic_set *ms) } file_public int -magic_setflags(struct magic_set *ms, int flags) +php_magic_setflags(struct magic_set *ms, int flags) { if (ms == NULL) return -1; @@ -325,13 +325,13 @@ magic_setflags(struct magic_set *ms, int flags) } file_public int -magic_version(void) +php_magic_version(void) { return MAGIC_VERSION; } file_public int -magic_setparam(struct magic_set *ms, int param, const void *val) +php_magic_setparam(struct magic_set *ms, int param, const void *val) { if (ms == NULL) return -1; @@ -374,7 +374,7 @@ magic_setparam(struct magic_set *ms, int param, const void *val) } file_public int -magic_getparam(struct magic_set *ms, int param, void *val) +php_magic_getparam(struct magic_set *ms, int param, void *val) { if (ms == NULL) return -1; diff --git a/ext/fileinfo/libmagic/magic.h b/ext/fileinfo/libmagic/magic.h index 781e91e355861..ab142b7bc4f03 100644 --- a/ext/fileinfo/libmagic/magic.h +++ b/ext/fileinfo/libmagic/magic.h @@ -123,27 +123,27 @@ extern "C" { #endif typedef struct magic_set *magic_t; -magic_t magic_open(int); -void magic_close(magic_t); +magic_t php_magic_open(int); +void php_magic_close(magic_t); -const char *magic_getpath(const char *, int); -const char *magic_file(magic_t, const char *); -const char *magic_stream(magic_t, php_stream *); -const char *magic_descriptor(magic_t, int); -const char *magic_buffer(magic_t, const void *, size_t); +const char *php_magic_getpath(const char *, int); +const char *php_magic_file(magic_t, const char *); +const char *php_magic_stream(magic_t, php_stream *); +const char *php_magic_descriptor(magic_t, int); +const char *php_magic_buffer(magic_t, const void *, size_t); -const char *magic_error(magic_t); -int magic_getflags(magic_t); -int magic_setflags(magic_t, int); +const char *php_magic_error(magic_t); +int php_magic_getflags(magic_t); +int php_magic_setflags(magic_t, int); -int magic_version(void); -int magic_load(magic_t, const char *); -int magic_load_buffers(magic_t, void **, size_t *, size_t); +int php_magic_version(void); +int php_magic_load(magic_t, const char *); +int php_magic_load_buffers(magic_t, void **, size_t *, size_t); -int magic_compile(magic_t, const char *); -int magic_check(magic_t, const char *); -int magic_list(magic_t, const char *); -int magic_errno(magic_t); +int php_magic_compile(magic_t, const char *); +int php_magic_check(magic_t, const char *); +int php_magic_list(magic_t, const char *); +int php_magic_errno(magic_t); #define MAGIC_PARAM_INDIR_MAX 0 #define MAGIC_PARAM_NAME_MAX 1 @@ -156,8 +156,8 @@ int magic_errno(magic_t); #define MAGIC_PARAM_ELF_SHSIZE_MAX 8 #define MAGIC_PARAM_MAGWARN_MAX 9 -int magic_setparam(magic_t, int, const void *); -int magic_getparam(magic_t, int, void *); +int php_magic_setparam(magic_t, int, const void *); +int php_magic_getparam(magic_t, int, void *); #ifdef __cplusplus };