diff --git a/file-secure_getenv.patch b/file-secure_getenv.patch index 4ff0854..4191c61 100644 --- a/file-secure_getenv.patch +++ b/file-secure_getenv.patch @@ -6,7 +6,7 @@ --- file-5.42/configure.ac +++ file-5.42/configure.ac 2022-06-13 08:34:50.347521415 +0000 -@@ -114,6 +114,8 @@ if test "$enable_xzlib" != "no"; then +@@ -122,6 +122,8 @@ if test "$enable_xzlib" != "no"; then fi AC_CHECK_TYPE([sig_t],[AC_DEFINE([HAVE_SIG_T],1,[Have sig_t type])],,[#include ]) @@ -17,7 +17,7 @@ AC_TYPE_SIZE_T --- file-5.42/src/file.h +++ file-5.42/src/file.h 2022-06-13 08:34:50.347521415 +0000 -@@ -706,4 +706,12 @@ static const char *rcsid(const char *p) +@@ -709,4 +709,12 @@ static const char *rcsid(const char *p) #define __RCSID(a) #endif diff --git a/file-zstd.patch b/file-zstd.patch new file mode 100644 index 0000000..24f4834 --- /dev/null +++ b/file-zstd.patch @@ -0,0 +1,179 @@ +Uses the streaming decompression API of libzstd to obtain inflated info for +magic processing from Zstandard compressed data. +--- + configure.ac | 19 ++++++++++++++ + src/compress.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 87 insertions(+) + +diff --git a/configure.ac b/configure.ac +index ffbe0f69..9172be9d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -49,6 +49,11 @@ AC_ARG_ENABLE([xzlib], + [AS_HELP_STRING([--disable-xzlib], [disable liblzma/xz compression support @<:@default=auto@:>@])]) + AC_MSG_RESULT($enable_xzlib) + ++AC_MSG_CHECKING(for zstdlib support) ++AC_ARG_ENABLE([zstdlib], ++[AS_HELP_STRING([--disable-zstdlib], [disable zstdlib compression support @<:@default=auto@:>@])]) ++AC_MSG_RESULT($enable_zstdlib) ++ + AC_MSG_CHECKING(for libseccomp support) + AC_ARG_ENABLE([libseccomp], + [AS_HELP_STRING([--disable-libseccomp], [disable libseccomp sandboxing @<:@default=auto@:>@])]) +@@ -112,6 +117,9 @@ fi + if test "$enable_xzlib" != "no"; then + AC_CHECK_HEADERS(lzma.h) + fi ++if test "$enable_zstdlib" != "no"; then ++ AC_CHECK_HEADERS(zstd.h zstd_errors.h) ++fi + AC_CHECK_TYPE([sig_t],[AC_DEFINE([HAVE_SIG_T],1,[Have sig_t type])],,[#include ]) + + dnl Checks for typedefs, structures, and compiler characteristics. +@@ -180,6 +188,9 @@ fi + if test "$enable_xzlib" != "no"; then + AC_CHECK_LIB(lzma, lzma_stream_decoder) + fi ++if test "$enable_zstdlib" != "no"; then ++ AC_CHECK_LIB(zstd, ZSTD_createDStream) ++fi + if test "$enable_libseccomp" != "no"; then + AC_CHECK_LIB(seccomp, seccomp_init) + fi +@@ -215,6 +226,14 @@ fi + if test "$ac_cv_header_lzma_h$ac_cv_lib_lzma_lzma_stream_decoder" = "yesyes"; then + AC_DEFINE([XZLIBSUPPORT], 1, [Enable xzlib compression support]) + fi ++if test "$enable_zstdlib" = "yes"; then ++ if test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" != "yesyes"; then ++ AC_MSG_ERROR([zstdlib support requested but not found]) ++ fi ++fi ++if test "$ac_cv_header_zstd_h$ac_cv_lib_zstd_ZSTD_createDStream" = "yesyes"; then ++ AC_DEFINE([ZSTDLIBSUPPORT], 1, [Enable zstdlib compression support]) ++fi + + AC_CONFIG_FILES([Makefile src/Makefile magic/Makefile tests/Makefile doc/Makefile python/Makefile libmagic.pc]) + AC_OUTPUT +diff --git a/src/compress.c b/src/compress.c +index 113077ae..abb8e766 100644 +--- a/src/compress.c ++++ b/src/compress.c +@@ -79,6 +79,12 @@ typedef void (*sig_t)(int); + #include + #endif + ++#if defined(HAVE_ZSTD_H) && defined(ZSTDLIBSUPPORT) ++#define BUILTIN_ZSTDLIB ++#include ++#include ++#endif ++ + #ifdef DEBUG + int tty = -1; + #define DPRINTF(...) do { \ +@@ -175,6 +181,7 @@ private const struct { + #define METH_FROZEN 2 + #define METH_BZIP 7 + #define METH_XZ 9 ++#define METH_ZSTD 12 + #define METH_LZMA 13 + #define METH_ZLIB 14 + { { .magic = "\037\235" }, 2, gzip_args, NULL }, /* 0, compressed */ +@@ -223,6 +230,10 @@ private int uncompressbzlib(const unsigned char *, unsigned char **, size_t, + private int uncompressxzlib(const unsigned char *, unsigned char **, size_t, + size_t *); + #endif ++#ifdef BUILTIN_ZSTDLIB ++private int uncompresszstd(const unsigned char *, unsigned char **, size_t, ++ size_t *); ++#endif + + static int makeerror(unsigned char **, size_t *, const char *, ...) + __attribute__((__format__(__printf__, 3, 4))); +@@ -697,6 +708,55 @@ err: + } + #endif + ++#ifdef BUILTIN_ZSTDLIB ++private int ++uncompresszstd(const unsigned char *old, unsigned char **newch, ++ size_t bytes_max, size_t *n) ++{ ++ size_t rc; ++ ZSTD_DStream *zstd; ++ ZSTD_inBuffer in; ++ ZSTD_outBuffer out; ++ ++ if ((zstd = ZSTD_createDStream()) == NULL) ++ return makeerror(newch, n, "No ZSTD decompression stream, %s", strerror(errno)); ++ ++ rc = ZSTD_DCtx_reset(zstd, ZSTD_reset_session_only); ++ if (ZSTD_isError(rc)) ++ goto err; ++ ++ if ((*newch = CAST(unsigned char *, malloc(bytes_max + 1))) == NULL) { ++ ZSTD_freeDStream(zstd); ++ return makeerror(newch, n, "No buffer, %s", strerror(errno)); ++ } ++ ++ in.src = CCAST(const void *, old); ++ in.size = *n; ++ in.pos = 0; ++ out.dst = RCAST(void *, *newch); ++ out.size = bytes_max; ++ out.pos = 0; ++ ++ rc = ZSTD_decompressStream(zstd, &out, &in); ++ if (ZSTD_isError(rc)) ++ goto err; ++ ++ *n = out.pos; ++ ++ ZSTD_freeDStream(zstd); ++ ++ /* let's keep the nul-terminate tradition */ ++ (*newch)[*n] = '\0'; ++ ++ return OKDATA; ++err: ++ ZSTD_freeDStream(zstd); ++ snprintf(RCAST(char *, *newch), bytes_max, "zstd error %d", ZSTD_getErrorCode(rc)); ++ *n = strlen(RCAST(char *, *newch)); ++ return ERRDATA; ++} ++#endif ++ + + static int + makeerror(unsigned char **buf, size_t *len, const char *fmt, ...) +@@ -863,6 +923,10 @@ methodname(size_t method) + case METH_XZ: + case METH_LZMA: + return "xzlib"; ++#endif ++#ifdef BUILTIN_ZSTDLIB ++ case METH_ZSTD: ++ return "zstd"; + #endif + default: + return compr[method].argv[0]; +@@ -899,6 +963,10 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old, + case METH_XZ: + case METH_LZMA: + return uncompressxzlib(old, newch, bytes_max, n); ++#endif ++#ifdef BUILTIN_ZSTDLIB ++ case METH_ZSTD: ++ return uncompresszstd(old, newch, bytes_max, n); + #endif + default: + break; +-- +2.37.3 + +-- +File mailing list +File@astron.com +https://mailman.astron.com/mailman/listinfo/file diff --git a/file.changes b/file.changes index aa68da1..424af8e 100644 --- a/file.changes +++ b/file.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Sep 14 08:58:50 UTC 2022 - Dr. Werner Fink + +- Add patch file-zstd.patch from upstream mailing list + * Add zstd decompression support + ------------------------------------------------------------------- Tue Sep 13 20:09:35 UTC 2022 - Dirk Müller diff --git a/file.spec b/file.spec index 7cc3fbd..5547cd1 100644 --- a/file.spec +++ b/file.spec @@ -25,6 +25,7 @@ BuildRequires: libtool BuildRequires: pkgconfig(bzip2) BuildRequires: pkgconfig(liblzma) BuildRequires: pkgconfig(libseccomp) +BuildRequires: pkgconfig(libzstd) BuildRequires: pkgconfig(zlib) URL: http://www.darwinsys.com/file/ # bug437293 @@ -62,6 +63,8 @@ Patch31: file-5.19-biorad.dif Patch32: file-5.19-clicfs.dif Patch37: file-secure_getenv.patch Patch39: file-5.28-btrfs-image.dif +# Upstream mailing list +Patch42: file-zstd.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build %global _sysconfdir /etc %global magicdir %{_datadir}/file @@ -106,6 +109,7 @@ to develop applications that require the magic "file" interface. %prep %setup -q -n file-%{version} +%patch42 -p1 %patch1 -p0 -b .misc %patch4 -p0 -b .conf %patch5 -p0 -b .tex diff --git a/python-magic.changes b/python-magic.changes index 5b4b11d..12fad9b 100644 --- a/python-magic.changes +++ b/python-magic.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Sep 14 09:00:26 UTC 2022 - Dr. Werner Fink + +- Update to 5.43 due to Dirk + ------------------------------------------------------------------- Sat Mar 19 18:01:52 UTC 2022 - Dirk Müller