Accepting request 1003495 from Base:System

- Add patch file-zstd.patch from upstream mailing list
  * Add zstd decompression support
- Run also upstream standard checks

- update to 5.43:
  * Add octal indirect magic
  * avoid infinite loop in non-wide code 
  * Obey MAGIC_CONTINUE with multiple magic files
  * Fix bug with large flist
  * PR/364: Detect non-nul-terminated core filenames from QEMU
  * PR/359: Add support for http://ndjson.org/ 
  * PR/362: Fix wide printing 
  * PR/358: Fix width for -f -
- drop file-boo1201350.patch (upstream)

- Update to 5.43 due to Dirk

OBS-URL: https://build.opensuse.org/request/show/1003495
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/file?expand=0&rev=131
This commit is contained in:
Dominique Leuenberger 2022-09-16 11:31:51 +00:00 committed by Git OBS Bridge
commit 3292e79cf1
18 changed files with 314 additions and 265 deletions

View File

@ -1,6 +1,8 @@
--- file-5.39/src/file.c.orig 2020-06-17 16:13:36.625305367 +0200
+++ file-5.39/src/file.c 2020-06-17 16:15:12.429553163 +0200
@@ -254,6 +254,8 @@
Index: file-5.43/src/file.c
===================================================================
--- file-5.43.orig/src/file.c
+++ file-5.43/src/file.c
@@ -260,6 +260,8 @@ main(int argc, char *argv[])
break;
case 'e':
case OPT_EXCLUDE_QUIET:
@ -9,7 +11,7 @@
for (i = 0; i < __arraycount(nv); i++)
if (strcmp(nv[i].name, optarg) == 0)
break;
@@ -266,7 +268,7 @@
@@ -272,7 +274,7 @@ main(int argc, char *argv[])
break;
case 'f':
@ -18,7 +20,7 @@
usage();
if (magic == NULL)
if ((magic = load(magicfile, flags)) == NULL)
@@ -276,6 +278,8 @@
@@ -282,6 +284,8 @@ main(int argc, char *argv[])
++didsomefiles;
break;
case 'F':
@ -27,7 +29,7 @@
separator = optarg;
break;
case 'i':
@@ -288,6 +292,8 @@
@@ -294,6 +298,8 @@ main(int argc, char *argv[])
action = FILE_LIST;
break;
case 'm':

View File

@ -2,9 +2,11 @@
magic/Magdir/images | 2 ++
1 file changed, 2 insertions(+)
--- magic/Magdir/images
+++ magic/Magdir/images 2022-06-13 08:30:37.596139595 +0000
@@ -1951,6 +1951,8 @@
Index: magic/Magdir/images
===================================================================
--- magic/Magdir/images.orig
+++ magic/Magdir/images
@@ -1969,6 +1969,8 @@
# https://web.archive.org/web/20050317223257/www.cs.ubc.ca/spider/ladic/text/biorad.txt
# Samples: https://www.loci.wisc.edu/software/sample-data
14 uleshort <2

View File

@ -2,9 +2,11 @@
src/apprentice.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- src/apprentice.c
+++ src/apprentice.c 2021-10-19 08:52:01.991343421 +0000
@@ -2608,7 +2608,7 @@ check_format_type(const char *ptr, int t
Index: src/apprentice.c
===================================================================
--- src/apprentice.c.orig
+++ src/apprentice.c
@@ -2619,7 +2619,7 @@ check_format_type(const char *ptr, int t
}
} else
h = 0;

View File

@ -2,9 +2,11 @@
magic/Magdir/archive | 5 +++++
1 file changed, 5 insertions(+)
--- magic/Magdir/archive
+++ magic/Magdir/archive 2019-02-21 06:49:05.298138025 +0000
@@ -1399,6 +1399,11 @@
Index: magic/Magdir/archive
===================================================================
--- magic/Magdir/archive.orig
+++ magic/Magdir/archive
@@ -1421,6 +1421,11 @@
0 string PK\x07\x08PK\x03\x04 Zip multi-volume archive data, at least PKZIP v2.50 to extract
!:mime application/zip
!:ext zip/cbz

View File

@ -2,9 +2,11 @@
src/readelf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- src/readelf.c
+++ src/readelf.c 2019-02-21 06:41:38.598573505 +0000
@@ -824,7 +824,7 @@ do_core_note(struct magic_set *ms, unsig
Index: src/readelf.c
===================================================================
--- src/readelf.c.orig
+++ src/readelf.c
@@ -825,7 +825,7 @@ do_core_note(struct magic_set *ms, unsig
default:
if (type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {
@ -13,7 +15,7 @@
unsigned char c;
/*
* Extract the program name. We assume
@@ -836,7 +836,9 @@ do_core_note(struct magic_set *ms, unsig
@@ -837,7 +837,9 @@ do_core_note(struct magic_set *ms, unsig
* If the characters aren't all printable,
* reject it.
*/

View File

@ -13,9 +13,10 @@ contained within the image.
magic/Magdir/filesystems | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
Index: file-5.43/magic/Magdir/filesystems
===================================================================
--- file-5.43.orig/magic/Magdir/filesystems
+++ file-5.43/magic/Magdir/filesystems
@@ -2302,20 +2302,29 @@
>>0x10060 string >\0 lockproto %s)

View File

@ -9,8 +9,10 @@
src/dcore.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 313 insertions(+), 68 deletions(-)
--- magic/Magdir/elf
+++ magic/Magdir/elf 2022-06-13 08:44:29.248838085 +0000
Index: magic/Magdir/elf
===================================================================
--- magic/Magdir/elf.orig
+++ magic/Magdir/elf
@@ -152,7 +152,7 @@
>18 leshort 47 Renesas H8/300H,
>18 leshort 48 Renesas H8S,
@ -20,8 +22,10 @@
>18 leshort 51 Stanford MIPS-X,
>18 leshort 52 Motorola Coldfire,
>18 leshort 53 Motorola M68HC12,
--- magic/Magdir/linux
+++ magic/Magdir/linux 2022-06-13 08:44:29.248838085 +0000
Index: magic/Magdir/linux
===================================================================
--- magic/Magdir/linux.orig
+++ magic/Magdir/linux
@@ -140,27 +140,31 @@
# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29
# Linux kernel boot images (i386 arch) (Wolfram Kleff)
@ -70,16 +74,20 @@
# This also matches new kernels, which were caught above by "HdrS".
0 belong 0xb8c0078e Linux kernel
>0x1e3 string Loading version 1.3.79 or older
--- magic/Magdir/msad
+++ magic/Magdir/msad 2022-06-13 08:44:29.248838085 +0000
Index: magic/Magdir/msad
===================================================================
--- /dev/null
+++ magic/Magdir/msad
@@ -0,0 +1,5 @@
+#------------------------------------------------------------------------------
+# msad: file(1) magic for msad
+# Microsoft visual C
+# This must precede the heuristic for raw G3 data
+4 string Standard\ Jet\ DB Microsoft Access Database
--- magic/Magdir/msdos
+++ magic/Magdir/msdos 2022-06-13 08:44:29.248838085 +0000
Index: magic/Magdir/msdos
===================================================================
--- magic/Magdir/msdos.orig
+++ magic/Magdir/msdos
@@ -145,9 +145,9 @@
>>(0x3c.l+22) leshort&0x0200 >0 (stripped to external PDB)
>>(0x3c.l+22) leshort&0x1000 >0 system file
@ -92,17 +100,19 @@
# hooray, there's a DOS extender using the PE format, with a valid PE
# executable inside (which just prints a message and exits if run in win)
@@ -635,7 +635,7 @@
# negative offset, must not lead into PSP
>1 short <-259
@@ -750,7 +750,7 @@
>1 leshort <-259
# that offset must be accessible
# add 10000h to jump at end of 64 KiB segment, add 1 for jump instruction and 2 for 16-bit offset
->>(1,s+65539) byte x
+>>(1.s+65539) byte x
# after jump next instruction for DEBUGGING!
#>>>&-1 ubelong x \b, NEXT instruction %#8.8x
>>>0 use msdos-com
# updated by Joerg Jenderek at Oct 2008,2015
--- magic/Makefile.am
+++ magic/Makefile.am 2022-06-13 08:44:29.248838085 +0000
Index: magic/Makefile.am
===================================================================
--- magic/Makefile.am.orig
+++ magic/Makefile.am
@@ -5,7 +5,7 @@ MAGIC_FRAGMENT_BASE = Magdir
MAGIC_DIR = $(top_srcdir)/magic
MAGIC_FRAGMENT_DIR = $(MAGIC_DIR)/$(MAGIC_FRAGMENT_BASE)
@ -120,7 +130,7 @@
$(MAGIC_FRAGMENT_DIR)/application \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/apt \
@@ -105,7 +104,6 @@ $(MAGIC_FRAGMENT_DIR)/erlang \
@@ -106,7 +105,6 @@ $(MAGIC_FRAGMENT_DIR)/erlang \
$(MAGIC_FRAGMENT_DIR)/espressif \
$(MAGIC_FRAGMENT_DIR)/esri \
$(MAGIC_FRAGMENT_DIR)/fcs \
@ -128,7 +138,7 @@
$(MAGIC_FRAGMENT_DIR)/finger \
$(MAGIC_FRAGMENT_DIR)/flash \
$(MAGIC_FRAGMENT_DIR)/flif \
@@ -150,6 +148,8 @@ $(MAGIC_FRAGMENT_DIR)/isz \
@@ -152,6 +150,8 @@ $(MAGIC_FRAGMENT_DIR)/isz \
$(MAGIC_FRAGMENT_DIR)/java \
$(MAGIC_FRAGMENT_DIR)/javascript \
$(MAGIC_FRAGMENT_DIR)/jpeg \
@ -137,7 +147,7 @@
$(MAGIC_FRAGMENT_DIR)/karma \
$(MAGIC_FRAGMENT_DIR)/kde \
$(MAGIC_FRAGMENT_DIR)/keepass \
@@ -160,7 +160,6 @@ $(MAGIC_FRAGMENT_DIR)/lammps \
@@ -162,7 +162,6 @@ $(MAGIC_FRAGMENT_DIR)/lammps \
$(MAGIC_FRAGMENT_DIR)/lecter \
$(MAGIC_FRAGMENT_DIR)/lex \
$(MAGIC_FRAGMENT_DIR)/lif \
@ -145,7 +155,7 @@
$(MAGIC_FRAGMENT_DIR)/lisp \
$(MAGIC_FRAGMENT_DIR)/llvm \
$(MAGIC_FRAGMENT_DIR)/locoscript \
@@ -168,7 +167,6 @@ $(MAGIC_FRAGMENT_DIR)/lua \
@@ -170,7 +169,6 @@ $(MAGIC_FRAGMENT_DIR)/lua \
$(MAGIC_FRAGMENT_DIR)/luks \
$(MAGIC_FRAGMENT_DIR)/m4 \
$(MAGIC_FRAGMENT_DIR)/mach \
@ -153,7 +163,7 @@
$(MAGIC_FRAGMENT_DIR)/macos \
$(MAGIC_FRAGMENT_DIR)/magic \
$(MAGIC_FRAGMENT_DIR)/mail.news \
@@ -192,11 +190,11 @@ $(MAGIC_FRAGMENT_DIR)/misctools \
@@ -194,11 +192,11 @@ $(MAGIC_FRAGMENT_DIR)/misctools \
$(MAGIC_FRAGMENT_DIR)/mkid \
$(MAGIC_FRAGMENT_DIR)/mlssa \
$(MAGIC_FRAGMENT_DIR)/mmdf \
@ -166,16 +176,16 @@
$(MAGIC_FRAGMENT_DIR)/msooxml \
$(MAGIC_FRAGMENT_DIR)/msvc \
$(MAGIC_FRAGMENT_DIR)/msx \
@@ -258,6 +256,8 @@ $(MAGIC_FRAGMENT_DIR)/python \
$(MAGIC_FRAGMENT_DIR)/qt \
@@ -261,6 +259,8 @@ $(MAGIC_FRAGMENT_DIR)/qt \
$(MAGIC_FRAGMENT_DIR)/revision \
$(MAGIC_FRAGMENT_DIR)/ringdove \
$(MAGIC_FRAGMENT_DIR)/riff \
+$(MAGIC_FRAGMENT_DIR)/apple \
+$(MAGIC_FRAGMENT_DIR)/macintosh \
$(MAGIC_FRAGMENT_DIR)/rpi \
$(MAGIC_FRAGMENT_DIR)/rpm \
$(MAGIC_FRAGMENT_DIR)/rpmsg \
@@ -347,9 +347,21 @@ EXTRA_DIST = \
@@ -351,9 +351,21 @@ EXTRA_DIST = \
$(MAGIC_DIR)/scripts/create_filemagic_flac \
$(MAGIC_FRAGMENTS)
@ -199,7 +209,7 @@
# FIXME: Build file natively as well so that it can be used to compile
# the target's magic file; for now we bail if the local version does not match
@@ -361,19 +373,22 @@ FILE_COMPILE = $(top_builddir)/src/file$
@@ -365,19 +377,22 @@ FILE_COMPILE = $(top_builddir)/src/file$
FILE_COMPILE_DEP = $(FILE_COMPILE)
endif
@ -238,9 +248,11 @@
+# fi)
+# $(FILE_COMPILE) -C -m magic
+# @rm -fr magic
--- magic/Makefile.in
+++ magic/Makefile.in 2022-06-13 08:44:29.248838085 +0000
@@ -280,7 +280,7 @@ top_srcdir = @top_srcdir@
Index: magic/Makefile.in
===================================================================
--- magic/Makefile.in.orig
+++ magic/Makefile.in
@@ -283,7 +283,7 @@ top_srcdir = @top_srcdir@
MAGIC_FRAGMENT_BASE = Magdir
MAGIC_DIR = $(top_srcdir)/magic
MAGIC_FRAGMENT_DIR = $(MAGIC_DIR)/$(MAGIC_FRAGMENT_BASE)
@ -249,7 +261,7 @@
MAGIC_FRAGMENTS = \
$(MAGIC_DIR)/Header \
$(MAGIC_DIR)/Localstuff \
@@ -298,7 +298,6 @@ $(MAGIC_FRAGMENT_DIR)/animation \
@@ -301,7 +301,6 @@ $(MAGIC_FRAGMENT_DIR)/animation \
$(MAGIC_FRAGMENT_DIR)/aout \
$(MAGIC_FRAGMENT_DIR)/apache \
$(MAGIC_FRAGMENT_DIR)/apl \
@ -257,7 +269,7 @@
$(MAGIC_FRAGMENT_DIR)/application \
$(MAGIC_FRAGMENT_DIR)/applix \
$(MAGIC_FRAGMENT_DIR)/apt \
@@ -379,7 +378,6 @@ $(MAGIC_FRAGMENT_DIR)/erlang \
@@ -383,7 +382,6 @@ $(MAGIC_FRAGMENT_DIR)/erlang \
$(MAGIC_FRAGMENT_DIR)/espressif \
$(MAGIC_FRAGMENT_DIR)/esri \
$(MAGIC_FRAGMENT_DIR)/fcs \
@ -265,7 +277,7 @@
$(MAGIC_FRAGMENT_DIR)/finger \
$(MAGIC_FRAGMENT_DIR)/flash \
$(MAGIC_FRAGMENT_DIR)/flif \
@@ -424,6 +422,8 @@ $(MAGIC_FRAGMENT_DIR)/isz \
@@ -429,6 +427,8 @@ $(MAGIC_FRAGMENT_DIR)/isz \
$(MAGIC_FRAGMENT_DIR)/java \
$(MAGIC_FRAGMENT_DIR)/javascript \
$(MAGIC_FRAGMENT_DIR)/jpeg \
@ -274,7 +286,7 @@
$(MAGIC_FRAGMENT_DIR)/karma \
$(MAGIC_FRAGMENT_DIR)/kde \
$(MAGIC_FRAGMENT_DIR)/keepass \
@@ -434,7 +434,6 @@ $(MAGIC_FRAGMENT_DIR)/lammps \
@@ -439,7 +439,6 @@ $(MAGIC_FRAGMENT_DIR)/lammps \
$(MAGIC_FRAGMENT_DIR)/lecter \
$(MAGIC_FRAGMENT_DIR)/lex \
$(MAGIC_FRAGMENT_DIR)/lif \
@ -282,7 +294,7 @@
$(MAGIC_FRAGMENT_DIR)/lisp \
$(MAGIC_FRAGMENT_DIR)/llvm \
$(MAGIC_FRAGMENT_DIR)/locoscript \
@@ -442,7 +441,6 @@ $(MAGIC_FRAGMENT_DIR)/lua \
@@ -447,7 +446,6 @@ $(MAGIC_FRAGMENT_DIR)/lua \
$(MAGIC_FRAGMENT_DIR)/luks \
$(MAGIC_FRAGMENT_DIR)/m4 \
$(MAGIC_FRAGMENT_DIR)/mach \
@ -290,7 +302,7 @@
$(MAGIC_FRAGMENT_DIR)/macos \
$(MAGIC_FRAGMENT_DIR)/magic \
$(MAGIC_FRAGMENT_DIR)/mail.news \
@@ -466,11 +464,11 @@ $(MAGIC_FRAGMENT_DIR)/misctools \
@@ -471,11 +469,11 @@ $(MAGIC_FRAGMENT_DIR)/misctools \
$(MAGIC_FRAGMENT_DIR)/mkid \
$(MAGIC_FRAGMENT_DIR)/mlssa \
$(MAGIC_FRAGMENT_DIR)/mmdf \
@ -303,16 +315,16 @@
$(MAGIC_FRAGMENT_DIR)/msooxml \
$(MAGIC_FRAGMENT_DIR)/msvc \
$(MAGIC_FRAGMENT_DIR)/msx \
@@ -532,6 +530,8 @@ $(MAGIC_FRAGMENT_DIR)/python \
$(MAGIC_FRAGMENT_DIR)/qt \
@@ -538,6 +536,8 @@ $(MAGIC_FRAGMENT_DIR)/qt \
$(MAGIC_FRAGMENT_DIR)/revision \
$(MAGIC_FRAGMENT_DIR)/ringdove \
$(MAGIC_FRAGMENT_DIR)/riff \
+$(MAGIC_FRAGMENT_DIR)/apple \
+$(MAGIC_FRAGMENT_DIR)/macintosh \
$(MAGIC_FRAGMENT_DIR)/rpi \
$(MAGIC_FRAGMENT_DIR)/rpm \
$(MAGIC_FRAGMENT_DIR)/rpmsg \
@@ -621,10 +621,22 @@ EXTRA_DIST = \
@@ -628,10 +628,22 @@ EXTRA_DIST = \
$(MAGIC_DIR)/scripts/create_filemagic_flac \
$(MAGIC_FRAGMENTS)
@ -336,7 +348,7 @@
# FIXME: Build file natively as well so that it can be used to compile
# the target's magic file; for now we bail if the local version does not match
@IS_CROSS_COMPILE_TRUE@FILE_COMPILE = file${EXEEXT}
@@ -849,23 +861,25 @@ uninstall-am: uninstall-pkgdataDATA
@@ -855,23 +867,25 @@ uninstall-am: uninstall-pkgdataDATA
.PRECIOUS: Makefile
@ -378,16 +390,20 @@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
--- src/Makefile.am
+++ src/Makefile.am 2022-06-13 08:44:29.248838085 +0000
Index: src/Makefile.am
===================================================================
--- src/Makefile.am.orig
+++ src/Makefile.am
@@ -1,4 +1,4 @@
-MAGIC = $(pkgdatadir)/magic
+MAGIC = $(sysconfdir)/magic:$(pkgdatadir)/magic
lib_LTLIBRARIES = libmagic.la
nodist_include_HEADERS = magic.h
--- src/dcore.c
+++ src/dcore.c 2022-06-13 08:44:29.248838085 +0000
Index: src/dcore.c
===================================================================
--- /dev/null
+++ src/dcore.c
@@ -0,0 +1,207 @@
+/*
+ * Show goo about ELF core files

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c076fb4d029c74073f15c43361ef572cfb868407d347190ba834af3b1639b0e4
size 1105846

View File

@ -1,6 +0,0 @@
-----BEGIN PGP SIGNATURE-----
iF0EABECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCYqNK1QAKCRBxESqxbLM7
Or2rAKDIx6yR4k5adLOh6+dwe3gHGeq7SwCffNuFkJgje9xr31P0KaZEPBdd91Q=
=cCEN
-----END PGP SIGNATURE-----

3
file-5.43.tar.gz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8c8015e91ae0e8d0321d94c78239892ef9dbc70c4ade0008c0e95894abfb1991
size 1162786

6
file-5.43.tar.gz.asc Normal file
View File

@ -0,0 +1,6 @@
-----BEGIN PGP SIGNATURE-----
iF0EABECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCYyDSYwAKCRBxESqxbLM7
Oq5DAJ4i24Hoo/BQ/twN6reZthvb2VyUsQCfb4+yj6JJW5C0fA++P/KYbrJChug=
=3+aN
-----END PGP SIGNATURE-----

View File

@ -1,186 +0,0 @@
From c80065fe6900be5e794941e29b32440e9969b1c3 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 4 Jul 2022 19:44:35 +0000
Subject: [PATCH 1/5] PR/362: ro-ee: fix wide char printing
---
src/file.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++-------------
src/file.h | 4 +-
src/funcs.c | 4 +-
3 files changed, 81 insertions(+), 24 deletions(-)
--- src/file.c
+++ src/file.c 2022-07-21 13:56:33.280169243 +0000
@@ -60,6 +60,12 @@ FILE_RCSID("@(#)$File: file.c,v 1.195 20
#ifdef HAVE_WCTYPE_H
#include <wctype.h>
#endif
+#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \
+ defined(HAVE_WCTYPE_H)
+#define FILE_WIDE_SUPPORT
+#else
+#include <ctype.h>
+#endif
#if defined(HAVE_GETOPT_H) && defined(HAVE_STRUCT_OPTION)
# include <getopt.h>
@@ -544,6 +550,58 @@ unwrap(struct magic_set *ms, const char
return e;
}
+private void
+file_octal(unsigned char c)
+{
+ putc('\\', stdout);
+ putc(((c >> 6) & 7) + '0', stdout);
+ putc(((c >> 3) & 7) + '0', stdout);
+ putc(((c >> 0) & 7) + '0', stdout);
+}
+
+private void
+fname_print(const char *inname)
+{
+ size_t n = strlen(inname);
+#ifdef FILE_WIDE_SUPPORT
+ mbstate_t state;
+ wchar_t nextchar;
+ size_t bytesconsumed;
+
+
+ (void)memset(&state, 0, sizeof(state));
+ while (n > 0) {
+ bytesconsumed = mbrtowc(&nextchar, inname, n, &state);
+ if (bytesconsumed == CAST(size_t, -1) ||
+ bytesconsumed == CAST(size_t, -2)) {
+ nextchar = *inname++;
+ n--;
+ (void)memset(&state, 0, sizeof(state));
+ file_octal(CAST(unsigned char, nextchar));
+ continue;
+ }
+ inname += bytesconsumed;
+ n -= bytesconsumed;
+ if (iswprint(nextchar)) {
+ printf("%lc", nextchar);
+ continue;
+ }
+ /* XXX: What if it is > 255? */
+ file_octal(CAST(unsigned char, nextchar));
+ }
+#else
+ size_t i;
+ for (i = 0; i < n; i++) {
+ unsigned char c = CAST(unsigned char, inname[i]);
+ if (isprint(c)) {
+ putc(c);
+ continue;
+ }
+ file_octal(c);
+ }
+#endif
+}
+
/*
* Called for each input file on the command line (or in a list of files)
*/
@@ -553,15 +611,13 @@ process(struct magic_set *ms, const char
const char *type, c = nulsep > 1 ? '\0' : '\n';
int std_in = strcmp(inname, "-") == 0;
int haderror = 0;
- size_t plen = 4 * wid + 1;
- char *pbuf, *pname;
-
- if ((pbuf = CAST(char *, malloc(plen))) == NULL)
- file_err(EXIT_FAILURE, "Can't allocate %zu bytes", plen);
if (wid > 0 && !bflag) {
- pname = file_printable(ms, pbuf, plen, inname, wid);
- (void)printf("%s", std_in ? "/dev/stdin" : pname);
+ const char *pname = std_in ? "/dev/stdin" : inname;
+ if ((ms->flags & MAGIC_RAW) == 0)
+ fname_print(pname);
+ else
+ (void)printf("%s", pname);
if (nulsep)
(void)putc('\0', stdout);
if (nulsep < 2) {
@@ -580,7 +636,6 @@ process(struct magic_set *ms, const char
}
if (nobuffer)
haderror |= fflush(stdout) != 0;
- free(pbuf);
return haderror || type == NULL;
}
@@ -588,35 +643,37 @@ protected size_t
file_mbswidth(struct magic_set *ms, const char *s)
{
size_t width = 0;
-#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) && \
- defined(HAVE_WCTYPE_H)
- size_t bytesconsumed, old_n, n;
+#ifdef FILE_WIDE_SUPPORT
+ size_t bytesconsumed, n;
mbstate_t state;
wchar_t nextchar;
- (void)memset(&state, 0, sizeof(mbstate_t));
- old_n = n = strlen(s);
+
+ (void)memset(&state, 0, sizeof(state));
+ n = strlen(s);
while (n > 0) {
bytesconsumed = mbrtowc(&nextchar, s, n, &state);
if (bytesconsumed == CAST(size_t, -1) ||
bytesconsumed == CAST(size_t, -2)) {
- /* Something went wrong, return something reasonable */
- return old_n;
+ nextchar = *s;
+ bytesconsumed = 1;
+ (void)memset(&state, 0, sizeof(state));
+ width += 4;
+ } else {
+ int w = wcwidth(nextchar);
+ width += ((ms->flags & MAGIC_RAW) != 0
+ || iswprint(nextchar)) ? (w > 0 ? w : 1) : 4;
}
- width += ((ms->flags & MAGIC_RAW) != 0
- || iswprint(nextchar)) ? wcwidth(nextchar) : 4;
s += bytesconsumed, n -= bytesconsumed;
}
- return width;
#else
while (*s) {
width += (ms->flags & MAGIC_RAW) != 0
|| isprint(CAST(unsigned char, *s)) ? 1 : 4;
}
-
- return strlen(s);
#endif
+ return width;
}
private void
--- src/file.h
+++ src/file.h 2022-07-21 13:56:33.280169243 +0000
@@ -575,7 +575,7 @@ protected size_t file_pstring_length_siz
const struct magic *);
protected size_t file_pstring_get_length(struct magic_set *,
const struct magic *, const char *);
-public char * file_printable(struct magic_set *, char *, size_t,
+protected char * file_printable(struct magic_set *, char *, size_t,
const char *, size_t);
#ifdef __EMX__
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
--- src/funcs.c
+++ src/funcs.c 2022-07-21 13:56:33.280169243 +0000
@@ -763,7 +763,7 @@ file_pop_buffer(struct magic_set *ms, fi
/*
* convert string to ascii printable format.
*/
-public char *
+protected char *
file_printable(struct magic_set *ms, char *buf, size_t bufsiz,
const char *str, size_t slen)
{

View File

@ -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 <signal.h>])
@ -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

179
file-zstd.patch Normal file
View File

@ -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 <signal.h>])
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 <lzma.h>
#endif
+#if defined(HAVE_ZSTD_H) && defined(ZSTDLIBSUPPORT)
+#define BUILTIN_ZSTDLIB
+#include <zstd.h>
+#include <zstd_errors.h>
+#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

View File

@ -1,3 +1,24 @@
-------------------------------------------------------------------
Wed Sep 14 08:58:50 UTC 2022 - Dr. Werner Fink <werner@suse.de>
- Add patch file-zstd.patch from upstream mailing list
* Add zstd decompression support
- Run also upstream standard checks
-------------------------------------------------------------------
Tue Sep 13 20:09:35 UTC 2022 - Dirk Müller <dmueller@suse.com>
- update to 5.43:
* Add octal indirect magic
* avoid infinite loop in non-wide code
* Obey MAGIC_CONTINUE with multiple magic files
* Fix bug with large flist
* PR/364: Detect non-nul-terminated core filenames from QEMU
* PR/359: Add support for http://ndjson.org/
* PR/362: Fix wide printing
* PR/358: Fix width for -f -
- drop file-boo1201350.patch (upstream)
-------------------------------------------------------------------
Thu Aug 25 19:31:39 UTC 2022 - Callum Farmer <gmbr3@opensuse.org>

View File

@ -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
@ -33,7 +34,7 @@ Obsoletes: file-64bit
%endif
#
# Set Version also in python-magic.spec
Version: 5.42
Version: 5.43
Release: 0
Summary: A Tool to Determine File Types
License: BSD-2-Clause
@ -62,8 +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 commits as patch
Patch42: file-boo1201350.patch
# Upstream mailing list
Patch42: file-zstd.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%global _sysconfdir /etc
%global magicdir %{_datadir}/file
@ -108,7 +109,7 @@ to develop applications that require the magic "file" interface.
%prep
%setup -q -n file-%{version}
%patch42 -p0
%patch42 -p1
%patch1 -p0 -b .misc
%patch4 -p0 -b .conf
%patch5 -p0 -b .tex
@ -162,6 +163,8 @@ install -s dcore %{buildroot}%{_bindir}
rm -f %{buildroot}%{_libdir}/*.la
%check
# Standard checks
make check
# Check out that the binary does not bail out:
LD_LIBRARY_PATH=%{buildroot}%{_libdir}
export LD_LIBRARY_PATH

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Wed Sep 14 09:00:26 UTC 2022 - Dr. Werner Fink <werner@suse.de>
- Update to 5.43 due to Dirk
-------------------------------------------------------------------
Sat Mar 19 18:01:52 UTC 2022 - Dirk Müller <dmueller@suse.com>

View File

@ -21,7 +21,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%global _miscdir %{_datadir}/misc
Name: python-magic
Version: 5.42
Version: 5.43
Release: 0
Summary: Python module to use libmagic
License: BSD-3-Clause AND BSD-4-Clause