Compare commits

...

No commits in common. 'i8c-beta' and 'c9' have entirely different histories.
i8c-beta ... c9

@ -1 +1 @@
31a67e4dc0a3d7a8d1b850429c3f625314700240 SOURCES/file-5.33.tar.gz
a5a8941a8e4c436fe22933db6a71c5161c3fb10b SOURCES/file-5.39.tar.gz

2
.gitignore vendored

@ -1 +1 @@
SOURCES/file-5.33.tar.gz
SOURCES/file-5.39.tar.gz

@ -1,28 +0,0 @@
From 8616080aecf07436e80a27f68c336382c1d1c22d Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sat, 9 Jun 2018 16:00:06 +0000
Subject: [PATCH] Avoid reading past the end of buffer (Rui Reis)
Upstream-commit: a642587a9c9e2dd7feacdf513c3643ce26ad3c22
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/readelf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 3df0836..d96a538 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -825,7 +825,8 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
cname = (unsigned char *)
&nbuf[doff + prpsoffsets(i)];
- for (cp = cname; *cp && isprint(*cp); cp++)
+ for (cp = cname; cp < nbuf + size && *cp
+ && isprint(*cp); cp++)
continue;
/*
* Linux apparently appends a space at the end
--
2.14.4

@ -1,68 +0,0 @@
diff -urp file-5.33.orig/src/softmagic.c file-5.33/src/softmagic.c
--- file-5.33.orig/src/softmagic.c 2020-12-14 12:26:50.286849841 -0500
+++ file-5.33/src/softmagic.c 2020-12-14 12:35:52.679166211 -0500
@@ -1748,7 +1748,8 @@ mget(struct magic_set *ms, struct magic
}
private uint64_t
-file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
+file_strncmp(const char *s1, const char *s2, size_t len, size_t maxlen,
+ uint32_t flags)
{
/*
* Convert the source args to unsigned here so that (1) the
@@ -1760,7 +1761,7 @@ file_strncmp(const char *s1, const char
const unsigned char *b = (const unsigned char *)s2;
uint32_t ws = flags & (STRING_COMPACT_WHITESPACE |
STRING_COMPACT_OPTIONAL_WHITESPACE);
- const unsigned char *eb = b + (ws ? strlen(s2) : len);
+ const unsigned char *eb = b + (ws ? maxlen : len);
uint64_t v;
/*
@@ -1818,7 +1819,8 @@ file_strncmp(const char *s1, const char
}
private uint64_t
-file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
+file_strncmp16(const char *a, const char *b, size_t len, size_t maxlen,
+ uint32_t flags)
{
/*
* XXX - The 16-bit string compare probably needs to be done
@@ -1826,7 +1828,7 @@ file_strncmp16(const char *a, const char
* At the moment, I am unsure.
*/
flags = 0;
- return file_strncmp(a, b, len, flags);
+ return file_strncmp(a, b, len, maxlen, flags);
}
private int
@@ -1954,13 +1956,15 @@ magiccheck(struct magic_set *ms, struct
case FILE_STRING:
case FILE_PSTRING:
l = 0;
- v = file_strncmp(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
+ v = file_strncmp(m->value.s, p->s, (size_t)m->vallen,
+ sizeof(p->s), m->str_flags);
break;
case FILE_BESTRING16:
case FILE_LESTRING16:
l = 0;
- v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
+ v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen,
+ sizeof(p->s), m->str_flags);
break;
case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
@@ -1979,7 +1983,7 @@ magiccheck(struct magic_set *ms, struct
return 0;
v = file_strncmp(m->value.s, ms->search.s + idx, slen,
- m->str_flags);
+ ms->search.s_len - idx, m->str_flags);
if (v == 0) { /* found match */
ms->search.offset += idx;
ms->search.rm_len = ms->search.s_len - idx;

@ -1,37 +0,0 @@
From fb1604080767501fde17eb601382e84f1c1ddca3 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 16 Jul 2018 12:30:41 +0000
Subject: [PATCH] remember to put a space between the version and the number,
plus more version parsing (Kamil Dudka)
Upstream-commit: 1a7f58c9f253e3b902bfb7a77afd8375b0b428b7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/fsav | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/magic/Magdir/fsav b/magic/Magdir/fsav
index 5714798..5d72ab9 100644
--- a/magic/Magdir/fsav
+++ b/magic/Magdir/fsav
@@ -48,13 +48,15 @@
>11 string >\0 Clam AntiVirus database %-.23s
>>34 string :
>>>35 string !: \b, version
->>>>35 string x \b%-.1s
->>>>>36 string !:
+>>>>35 string x \b %-.1s
+>>>>>36 string !:
>>>>>>36 string x \b%-.1s
>>>>>>>37 string !:
>>>>>>>>37 string x \b%-.1s
>>>>>>>>>38 string !:
>>>>>>>>>>38 string x \b%-.1s
+>>>>>>>>>>>39 string !:
+>>>>>>>>>>>>39 string x \b%-.1s
>512 string \037\213 \b, gzipped
>769 string ustar\0 \b, tarred
--
2.14.4

@ -1,31 +0,0 @@
From 7bd1d499157caa391082f594d197f49f5327bd56 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Wed, 1 Aug 2018 09:59:45 +0000
Subject: [PATCH] fix leak on error, found by coverity.
Upstream-commit: e0805be4909e47dac47bab9d0caf3725da43e645
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/compress.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/compress.c b/src/compress.c
index 184011b..cb11303 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -249,8 +249,11 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name)
* XXX: If file_buffer fails here, we overwrite
* the compressed text. FIXME.
*/
- if (file_buffer(ms, -1, NULL, buf, nbytes) == -1)
+ if (file_buffer(ms, -1, NULL, buf, nbytes) == -1) {
+ if (file_pop_buffer(ms, pb) != NULL)
+ abort();
goto error;
+ }
if ((rbuf = file_pop_buffer(ms, pb)) != NULL) {
if (file_printf(ms, "%s", rbuf) == -1) {
free(rbuf);
--
2.17.2

@ -1,11 +1,11 @@
diff --git a/src/compress.c b/src/compress.c
index cb11303..5677412 100644
index ba1e3d7..6846d66 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -723,25 +723,24 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
@@ -932,23 +932,23 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
rv = OKDATA;
if ((r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0)) > 0)
break;
r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0);
if (r <= 0) {
- DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
- r != -1 ? strerror(errno) : "no data");
-
@ -13,6 +13,16 @@ index cb11303..5677412 100644
- if (r == 0 &&
- (r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0)
- {
- r = filter_error(*newch, r);
- goto ok;
- }
- free(*newch);
- if (r == 0)
- rv = makeerror(newch, n, "Read failed, %s",
- strerror(errno));
- else
- rv = makeerror(newch, n, "No data");
- goto err;
+ if (r < 0) {
+ rv = ERRDATA;
+ DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
@ -20,23 +30,16 @@ index cb11303..5677412 100644
+ goto err;
+ } else if ((r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0){
+ rv = ERRDATA;
r = filter_error(*newch, r);
break;
}
- free(*newch);
if (r == 0)
- rv = makeerror(newch, n, "Read failed, %s",
- strerror(errno));
- else
- rv = makeerror(newch, n, "No data");
+ break;
+ r = filter_error(*newch, r);
+ goto ok;
+ }
+ if (r == 0)
+ goto ok;
+ free(*newch);
+ rv = ERRDATA;
+ rv = makeerror(newch, n, "Read stderr failed, %s",
+ strerror(errno));
goto err;
+ goto err;
}
-
ok:
*n = r;
/* NUL terminate, as every buffer is handled here. */
(*newch)[*n] = '\0';

@ -1,30 +0,0 @@
From f0e846528e1c839ab44895a1f13d167a4ad8def3 Mon Sep 17 00:00:00 2001
From: Marek Cermak <macermak@redhat.com>
Date: Wed, 20 Dec 2017 16:18:46 +0100
Subject: [PATCH] Resolves: #1515180 - image/gif classifed as
application/octet-stream
https://bugzilla.redhat.com/show_bug.cgi?id=1515180
Signed-off-by: Marek Cermak <macermak@redhat.com>
---
magic/Magdir/images | 2 ++
1 file changed, 2 insertions(+)
diff --git a/magic/Magdir/images b/magic/Magdir/images
index 69e8e90f..76f7e7da 100644
--- a/magic/Magdir/images
+++ b/magic/Magdir/images
@@ -468,7 +468,9 @@
!:mime image/x-unknown
# GIF
+# Strength set up to beat 0x55AA DOS/MBR signature word lookups (+65)
0 string GIF8 GIF image data
+!:strength +80
!:mime image/gif
!:apple 8BIMGIFf
>4 string 7a \b, version 8%s,
--
2.13.6

@ -1,22 +0,0 @@
diff -urp file-5.33.orig/magic/Magdir/python file-5.33/magic/Magdir/python
--- file-5.33.orig/magic/Magdir/python 2020-12-17 13:19:08.610803723 -0500
+++ file-5.33/magic/Magdir/python 2020-12-17 13:26:07.346954161 -0500
@@ -43,6 +43,18 @@
!:strength + 15
!:mime text/x-python
+0 search/1/wt #!\ /usr/libexec/platform-python Python script text executable
+!:strength + 15
+!:mime text/x-python
+
+0 search/1/wt #!\ /usr/bin/python2 Python script text executable
+!:strength + 15
+!:mime text/x-python
+
+0 search/1/wt #!\ /usr/bin/python3 Python script text executable
+!:strength + 15
+!:mime text/x-python
+
# from module.submodule import func1, func2
0 regex \^from[\040\t\f\r\n]+([A-Za-z0-9_]|\\.)+[\040\t\f\r\n]+import.*$ Python script text executable

@ -1,24 +0,0 @@
diff --git a/magic/Magdir/msooxml b/magic/Magdir/msooxml
index bde098e..7d0bcc7 100644
--- a/magic/Magdir/msooxml
+++ b/magic/Magdir/msooxml
@@ -28,16 +28,16 @@
# skip to the second local file header
# since some documents include a 520-byte extra field following the file
# header, we need to scan for the next header
->>(18.l+49) search/2000 PK\003\004
+>>(18.l+49) search/6000 PK\003\004
# now skip to the *third* local file header; again, we need to scan due to a
# 520-byte extra field following the file header
->>>&26 search/1000 PK\003\004
+>>>&26 search/6000 PK\003\004
# and check the subdirectory name to determine which type of OOXML
# file we have. Correct the mimetype with the registered ones:
# http://technet.microsoft.com/en-us/library/cc179224.aspx
>>>>&26 use msooxml
>>>>&26 default x
# OpenOffice/Libreoffice orders ZIP entry differently, so check the 4th file
->>>>>&26 search/1000 PK\003\004
+>>>>>&26 search/6000 PK\003\004
>>>>>>&26 use msooxml
>>>>>>&26 default x Microsoft OOXML

@ -1,35 +0,0 @@
diff -urp file-5.33.orig/magic/Magdir/commands file-5.33/magic/Magdir/commands
--- file-5.33.orig/magic/Magdir/commands 2017-08-14 03:40:38.000000000 -0400
+++ file-5.33/magic/Magdir/commands 2020-12-17 13:30:07.063162185 -0500
@@ -8,6 +8,8 @@
!:mime text/x-shellscript
0 string/wb #!\ /bin/sh POSIX shell script executable (binary data)
!:mime text/x-shellscript
+0 string/w #!\ /usr/bin/sh Shell script text executable
+!:mime text/x-shellscript
0 string/wt #!\ /bin/csh C shell script text executable
!:mime text/x-shellscript
diff -urp file-5.33.orig/magic/Magdir/javascript file-5.33/magic/Magdir/javascript
--- file-5.33.orig/magic/Magdir/javascript 2012-06-16 09:30:36.000000000 -0400
+++ file-5.33/magic/Magdir/javascript 2020-12-17 13:36:56.276843745 -0500
@@ -15,3 +15,5 @@
!:mime application/javascript
0 search/1 #!/usr/bin/env\ nodejs Node.js script text executable
!:mime application/javascript
+0 string/wt #!\ /usr/bin/gjs Gnome Javascript text executable
+!:mime text/javascript
diff -urp file-5.33.orig/magic/Magdir/tcl file-5.33/magic/Magdir/tcl
--- file-5.33.orig/magic/Magdir/tcl 2014-01-08 17:29:21.000000000 -0500
+++ file-5.33/magic/Magdir/tcl 2020-12-17 13:36:20.855391803 -0500
@@ -12,6 +12,10 @@
!:mime text/x-tcl
0 search/1 #!\ /usr/bin/env\ tcl Tcl script text executable
!:mime text/x-tcl
+0 string/wt #!\ /usr/bin/jimsh Jim TCL text executable
+!:mime text/x-tcl
+0 search/1/wt #!\ /usr/bin/tclsh Tcl/Tk script text executable
+!:mime text/x-tcl
0 search/1/w #!\ /usr/bin/wish Tcl/Tk script text executable
!:mime text/x-tcl
0 search/1/w #!\ /usr/local/bin/wish Tcl/Tk script text executable

@ -1,34 +0,0 @@
From 719116b196fd873f5a463dfdb0fd6258cee51591 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Tue, 22 May 2018 18:18:06 +0200
Subject: [PATCH] Revert "add a conditional in description"
Upstream-commit: 6876ebadcdf27224b3ffa9dfa4343127aa97c9b2
... and partially revert upstream commit
7dbecfe406a6bb2de1fe7ec2fe413dcd8871ac74
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/elf | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index 7fd5de1..dba5a73 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -48,9 +48,8 @@
!:mime application/x-object
>16 leshort 2 executable,
!:mime application/x-executable
->16 leshort 3 ${x?pie executable:shared object}
-
-!:mime application/x-${x?pie-executable:sharedlib}
+>16 leshort 3 shared object,
+!:mime application/x-sharedlib
>16 leshort 4 core file
!:mime application/x-coredump
# Core file detection is not reliable.
--
2.14.3

@ -1,35 +0,0 @@
From ed6062995ae60d6772f2dabc39e03cbf28ee7343 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 16 Jul 2018 12:32:08 +0000
Subject: [PATCH] more info for ppc swapspace (Kamil Dudka)
Upstream-commit: 65f9c7053548df8945df600c07123c9151531ee6
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/linux | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/magic/Magdir/linux b/magic/Magdir/linux
index 0630a8a..11e9237 100644
--- a/magic/Magdir/linux
+++ b/magic/Magdir/linux
@@ -94,6 +94,16 @@
# From Daniel Novotny <dnovotny@redhat.com>
# swap file for PowerPC
65526 string SWAPSPACE2 Linux/ppc swap file
+>0x400 long x version %d,
+>0x404 long x size %d pages,
+>1052 string \0 no label,
+>1052 string >\0 LABEL=%s,
+>0x40c belong x UUID=%08x
+>0x410 beshort x \b-%04x
+>0x412 beshort x \b-%04x
+>0x414 beshort x \b-%04x
+>0x416 belong x \b-%08x
+>0x41a beshort x \b%04x
16374 string SWAPSPACE2 Linux/ia64 swap file
#
# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>
--
2.14.4

@ -1,23 +0,0 @@
diff -urp file-5.33.orig/magic/Magdir/python file-5.33/magic/Magdir/python
--- file-5.33.orig/magic/Magdir/python 2017-08-14 03:40:38.000000000 -0400
+++ file-5.33/magic/Magdir/python 2020-12-14 12:24:42.084905613 -0500
@@ -30,16 +30,16 @@
0 belong 0x3e0d0d0a python 3.7 byte-compiled
-0 search/1/w #!\ /usr/bin/python Python script text executable
+0 search/1/w #!\040/usr/bin/python Python script text executable
!:strength + 15
!:mime text/x-python
-0 search/1/w #!\ /usr/local/bin/python Python script text executable
+0 search/1/w #!\040/usr/local/bin/python Python script text executable
!:strength + 15
!:mime text/x-python
0 search/1 #!/usr/bin/env\ python Python script text executable
!:strength + 15
!:mime text/x-python
-0 search/10 #!\ /usr/bin/env\ python Python script text executable
+0 search/10 #!\040/usr/bin/env\ python Python script text executable
!:strength + 15
!:mime text/x-python

@ -1,53 +0,0 @@
From 4ae8a24b5ccbee904875a10b7b2301369080a88d Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sun, 6 May 2018 16:36:41 +0000
Subject: [PATCH] add more syscalls; newfstatat is used for stat'ing the magic
file, getdents64 is used for getting the magic entries during compilation.
Upstream-commit: aeddbff330fad0edff2ab4b02dbf0863cd593c3c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/seccomp.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/seccomp.c b/src/seccomp.c
index 7c8a3144..481a5624 100644
--- a/src/seccomp.c
+++ b/src/seccomp.c
@@ -59,12 +59,7 @@ enable_sandbox_basic(void)
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
return -1;
-#if 0
- // prevent escape via ptrace
- prctl(PR_SET_DUMPABLE, 0);
-#endif
-
- if (prctl (PR_SET_DUMPABLE, 0, 0, 0, 0) == -1)
+ if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) == -1)
return -1;
// initialize the filter
@@ -171,6 +166,9 @@ enable_sandbox_full(void)
ALLOW_RULE(fcntl);
ALLOW_RULE(fstat);
ALLOW_RULE(getdents);
+#ifdef __NR_getdents64
+ ALLOW_RULE(getdents64);
+#endif
ALLOW_RULE(ioctl);
ALLOW_RULE(lseek);
ALLOW_RULE(lstat);
@@ -178,6 +176,9 @@ enable_sandbox_full(void)
ALLOW_RULE(mprotect);
ALLOW_RULE(mremap);
ALLOW_RULE(munmap);
+#ifdef __NR_newfstatat
+ ALLOW_RULE(newfstatat);
+#endif
ALLOW_RULE(open);
ALLOW_RULE(openat);
ALLOW_RULE(pread64);
--
2.17.0

@ -1,236 +0,0 @@
From 3951ed6ab1ba4b7d6d4d2dd5700858c470627c46 Mon Sep 17 00:00:00 2001
From: Vincent Mihalkovic <vmihalko@redhat.com>
Date: Thu, 9 Feb 2023 16:46:43 +0100
Subject: [PATCH] store copy of the mode info in the magic_set
---
src/file.h | 1 +
src/funcs.c | 53 +++++++++++++++++++++++++++++++------------------
src/softmagic.c | 27 +++++++++++--------------
3 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/src/file.h b/src/file.h
index 66598bc..b3d015d 100644
--- a/src/file.h
+++ b/src/file.h
@@ -413,6 +413,7 @@ struct magic_set {
#define EVENT_HAD_ERR 0x01
const char *file;
size_t line; /* current magic line number */
+ mode_t mode; /* copy of current stat mode */
/* data for searches */
struct {
diff --git a/src/funcs.c b/src/funcs.c
index f59f4a1..0bf92fe 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.94 2017/11/02 20:25:39 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.95 2018/05/24 18:09:17 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -183,9 +183,11 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
const char *type = "application/octet-stream";
const char *def = "data";
const char *ftype = NULL;
+ char *rbuf = NULL;
struct buffer b;
buffer_init(&b, fd, buf, nb);
+ ms->mode = b.st.st_mode;
if (nb == 0) {
def = "empty";
@@ -248,31 +250,43 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__u
goto done;
}
}
+#ifdef BUILTIN_ELF
+ if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && nb > 5 && fd != -1) {
+ file_pushbuf_t *pb;
+ /*
+ * We matched something in the file, so this
+ * *might* be an ELF file, and the file is at
+ * least 5 bytes long, so if it's an ELF file
+ * it has at least one byte past the ELF magic
+ * number - try extracting information from the
+ * ELF headers that cannot easily be extracted
+ * with rules in the magic file. We we don't
+ * print the information yet.
+ */
+ if ((pb = file_push_buffer(ms)) == NULL)
+ return -1;
+
+ rv = file_tryelf(ms, &b);
+ rbuf = file_pop_buffer(ms, pb);
+ if (rv != 1) {
+ free(rbuf);
+ rbuf = NULL;
+ }
+ if ((ms->flags & MAGIC_DEBUG) != 0)
+ (void)fprintf(stderr, "[try elf %d]\n", m);
+ }
+#endif
/* try soft magic tests */
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) {
m = file_softmagic(ms, &b, NULL, NULL, BINTEST, looks_text);
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "[try softmagic %d]\n", m);
+ if (m == 1 && rbuf) {
+ if (file_printf(ms, "%s", rbuf) == -1)
+ goto done;
+ }
if (m) {
-#ifdef BUILTIN_ELF
- if ((ms->flags & MAGIC_NO_CHECK_ELF) == 0 && m == 1 &&
- nb > 5 && fd != -1) {
- /*
- * We matched something in the file, so this
- * *might* be an ELF file, and the file is at
- * least 5 bytes long, so if it's an ELF file
- * it has at least one byte past the ELF magic
- * number - try extracting information from the
- * ELF headers that cannot easily * be
- * extracted with rules in the magic file.
- */
- m = file_tryelf(ms, &b);
- if ((ms->flags & MAGIC_DEBUG) != 0)
- (void)fprintf(stderr, "[try elf %d]\n",
- m);
- }
-#endif
if (checkdone(ms, &rv))
goto done;
}
@@ -318,6 +332,7 @@ simple:
#if HAVE_FORK
done_encoding:
#endif
+ free(rbuf);
buffer_fini(&b);
if (rv)
return rv;
diff --git a/src/softmagic.c b/src/softmagic.c
index 57b4677..0197ec4 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -54,8 +54,7 @@ private int mget(struct magic_set *, struct magic *, const struct buffer *,
private int msetoffset(struct magic_set *, struct magic *, struct buffer *,
const struct buffer *, size_t, unsigned int);
private int magiccheck(struct magic_set *, struct magic *);
-private int32_t mprint(struct magic_set *, struct magic *,
- const struct buffer *);
+private int32_t mprint(struct magic_set *, struct magic *);
private int moffset(struct magic_set *, struct magic *, const struct buffer *,
int32_t *);
private void mdebug(uint32_t, const char *, size_t);
@@ -63,8 +62,7 @@ private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
const unsigned char *, uint32_t, size_t, struct magic *);
private int mconvert(struct magic_set *, struct magic *, int);
private int print_sep(struct magic_set *, int);
-private int handle_annotation(struct magic_set *, struct magic *,
- const struct buffer *, int);
+private int handle_annotation(struct magic_set *, struct magic *, int);
private int cvt_8(union VALUETYPE *, const struct magic *);
private int cvt_16(union VALUETYPE *, const struct magic *);
private int cvt_32(union VALUETYPE *, const struct magic *);
@@ -241,7 +239,7 @@ flush:
goto flush;
}
- if ((e = handle_annotation(ms, m, b, firstline)) != 0) {
+ if ((e = handle_annotation(ms, m, firstline)) != 0) {
*need_separator = 1;
*printed_something = 1;
*returnval = 1;
@@ -259,7 +257,7 @@ flush:
return -1;
}
- if (print && mprint(ms, m, b) == -1)
+ if (print && mprint(ms, m) == -1)
return -1;
switch (moffset(ms, m, &bb, &ms->c.li[cont_level].off)) {
@@ -340,7 +338,7 @@ flush:
} else
ms->c.li[cont_level].got_match = 1;
- if ((e = handle_annotation(ms, m, b, firstline))
+ if ((e = handle_annotation(ms, m, firstline))
!= 0) {
*need_separator = 1;
*printed_something = 1;
@@ -374,7 +372,7 @@ flush:
return -1;
*need_separator = 0;
}
- if (print && mprint(ms, m, b) == -1)
+ if (print && mprint(ms, m) == -1)
return -1;
switch (moffset(ms, m, &bb,
@@ -454,7 +452,7 @@ strndup(const char *str, size_t n)
#endif /* HAVE_STRNDUP */
static int
-varexpand(char *buf, size_t len, const struct buffer *b, const char *str)
+varexpand(struct magic_set *ms, char *buf, size_t len, const char *str)
{
const char *ptr, *sptr, *e, *t, *ee, *et;
size_t l;
@@ -479,7 +477,7 @@ varexpand(char *buf, size_t len, const struct buffer *b, const char *str)
return -1;
switch (*ptr) {
case 'x':
- if (b->st.st_mode & 0111) {
+ if (ms->mode & 0111) {
ptr = t;
l = et - t;
} else {
@@ -509,7 +507,7 @@ varexpand(char *buf, size_t len, const struct buffer *b, const char *str)
private int32_t
-mprint(struct magic_set *ms, struct magic *m, const struct buffer *b)
+mprint(struct magic_set *ms, struct magic *m)
{
uint64_t v;
float vf;
@@ -519,7 +517,7 @@ mprint(struct magic_set *ms, struct magic *m, const struct buffer *b)
const char *desc;
union VALUETYPE *p = &ms->ms_value;
- if (varexpand(ebuf, sizeof(ebuf), b, m->desc) == -1)
+ if (varexpand(ms, ebuf, sizeof(ebuf), m->desc) == -1)
desc = m->desc;
else
desc = ebuf;
@@ -2166,8 +2164,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
}
private int
-handle_annotation(struct magic_set *ms, struct magic *m, const struct buffer *b,
- int firstline)
+handle_annotation(struct magic_set *ms, struct magic *m, int firstline)
{
if ((ms->flags & MAGIC_APPLE) && m->apple[0]) {
if (!firstline && file_printf(ms, "\n- ") == -1)
@@ -2188,7 +2185,7 @@ handle_annotation(struct magic_set *ms, struct magic *m, const struct buffer *b,
const char *p;
if (!firstline && file_printf(ms, "\n- ") == -1)
return -1;
- if (varexpand(buf, sizeof(buf), b, m->mimetype) == -1)
+ if (varexpand(ms, buf, sizeof(buf), m->mimetype) == -1)
p = m->mimetype;
else
p = buf;
--
2.39.1

@ -1,767 +0,0 @@
From 493e2676626b530a45fcc17040915f34fa0c5dd3 Mon Sep 17 00:00:00 2001
From: Vincent Mihalkovic <vmihalko@redhat.com>
Date: Mon, 6 Feb 2023 14:39:29 +0100
Subject: [PATCH] add parsing for dynamic sections
9109a696f3289ba00eaa222fd432755ec4287e28
---
src/readelf.c | 295 +++++++++++++++++++++++++++++++-------------------
src/readelf.h | 103 ++++++++++++++++++
2 files changed, 289 insertions(+), 109 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index c101483..cdc211f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -62,13 +62,12 @@ private uint64_t getu64(int, uint64_t);
#define MAX_PHNUM 128
#define MAX_SHNUM 32768
-#define SIZE_UNKNOWN ((off_t)-1)
+#define SIZE_UNKNOWN CAST(off_t, -1)
private int
toomany(struct magic_set *ms, const char *name, uint16_t num)
{
- if (file_printf(ms, ", too many %s (%u)", name, num
- ) == -1)
+ if (file_printf(ms, ", too many %s (%u)", name, num) == -1)
return -1;
return 0;
}
@@ -143,54 +142,55 @@ getu64(int swap, uint64_t value)
#define elf_getu64(swap, value) getu64(swap, value)
#define xsh_addr (clazz == ELFCLASS32 \
- ? (void *)&sh32 \
- : (void *)&sh64)
+ ? CAST(void *, &sh32) \
+ : CAST(void *, &sh64))
#define xsh_sizeof (clazz == ELFCLASS32 \
? sizeof(sh32) \
: sizeof(sh64))
-#define xsh_size (size_t)(clazz == ELFCLASS32 \
+#define xsh_size CAST(size_t, (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_size) \
- : elf_getu64(swap, sh64.sh_size))
-#define xsh_offset (off_t)(clazz == ELFCLASS32 \
+ : elf_getu64(swap, sh64.sh_size)))
+#define xsh_offset CAST(off_t, (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_offset) \
- : elf_getu64(swap, sh64.sh_offset))
+ : elf_getu64(swap, sh64.sh_offset)))
#define xsh_type (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_type) \
: elf_getu32(swap, sh64.sh_type))
#define xsh_name (clazz == ELFCLASS32 \
? elf_getu32(swap, sh32.sh_name) \
: elf_getu32(swap, sh64.sh_name))
+
#define xph_addr (clazz == ELFCLASS32 \
- ? (void *) &ph32 \
- : (void *) &ph64)
+ ? CAST(void *, &ph32) \
+ : CAST(void *, &ph64))
#define xph_sizeof (clazz == ELFCLASS32 \
? sizeof(ph32) \
: sizeof(ph64))
#define xph_type (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_type) \
: elf_getu32(swap, ph64.p_type))
-#define xph_offset (off_t)(clazz == ELFCLASS32 \
+#define xph_offset CAST(off_t, (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_offset) \
- : elf_getu64(swap, ph64.p_offset))
-#define xph_align (size_t)((clazz == ELFCLASS32 \
- ? (off_t) (ph32.p_align ? \
- elf_getu32(swap, ph32.p_align) : 4) \
- : (off_t) (ph64.p_align ? \
- elf_getu64(swap, ph64.p_align) : 4)))
-#define xph_vaddr (size_t)((clazz == ELFCLASS32 \
- ? (off_t) (ph32.p_vaddr ? \
- elf_getu32(swap, ph32.p_vaddr) : 4) \
- : (off_t) (ph64.p_vaddr ? \
- elf_getu64(swap, ph64.p_vaddr) : 4)))
-#define xph_filesz (size_t)((clazz == ELFCLASS32 \
+ : elf_getu64(swap, ph64.p_offset)))
+#define xph_align CAST(size_t, (clazz == ELFCLASS32 \
+ ? CAST(off_t, (ph32.p_align ? \
+ elf_getu32(swap, ph32.p_align) : 4))\
+ : CAST(off_t, (ph64.p_align ? \
+ elf_getu64(swap, ph64.p_align) : 4))))
+#define xph_vaddr CAST(size_t, (clazz == ELFCLASS32 \
+ ? CAST(off_t, (ph32.p_vaddr ? \
+ elf_getu32(swap, ph32.p_vaddr) : 4))\
+ : CAST(off_t, (ph64.p_vaddr ? \
+ elf_getu64(swap, ph64.p_vaddr) : 4))))
+#define xph_filesz CAST(size_t, (clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_filesz) \
: elf_getu64(swap, ph64.p_filesz)))
-#define xnh_addr (clazz == ELFCLASS32 \
- ? (void *)&nh32 \
- : (void *)&nh64)
-#define xph_memsz (size_t)((clazz == ELFCLASS32 \
+#define xph_memsz CAST(size_t, ((clazz == ELFCLASS32 \
? elf_getu32(swap, ph32.p_memsz) \
- : elf_getu64(swap, ph64.p_memsz)))
+ : elf_getu64(swap, ph64.p_memsz))))
+#define xnh_addr (clazz == ELFCLASS32 \
+ ? CAST(void *, &nh32) \
+ : CAST(void *, &nh64))
#define xnh_sizeof (clazz == ELFCLASS32 \
? sizeof(nh32) \
: sizeof(nh64))
@@ -203,24 +203,36 @@ getu64(int swap, uint64_t value)
#define xnh_descsz (clazz == ELFCLASS32 \
? elf_getu32(swap, nh32.n_descsz) \
: elf_getu32(swap, nh64.n_descsz))
-#define prpsoffsets(i) (clazz == ELFCLASS32 \
- ? prpsoffsets32[i] \
- : prpsoffsets64[i])
+
+#define xdh_addr (clazz == ELFCLASS32 \
+ ? CAST(void *, &dh32) \
+ : CAST(void *, &dh64))
+#define xdh_sizeof (clazz == ELFCLASS32 \
+ ? sizeof(dh32) \
+ : sizeof(dh64))
+#define xdh_tag (clazz == ELFCLASS32 \
+ ? elf_getu32(swap, dh32.d_tag) \
+ : elf_getu64(swap, dh64.d_tag))
+#define xdh_val (clazz == ELFCLASS32 \
+ ? elf_getu32(swap, dh32.d_un.d_val) \
+ : elf_getu64(swap, dh64.d_un.d_val))
+
#define xcap_addr (clazz == ELFCLASS32 \
- ? (void *)&cap32 \
- : (void *)&cap64)
+ ? CAST(void *, &cap32) \
+ : CAST(void *, &cap64))
#define xcap_sizeof (clazz == ELFCLASS32 \
- ? sizeof cap32 \
- : sizeof cap64)
+ ? sizeof(cap32) \
+ : sizeof(cap64))
#define xcap_tag (clazz == ELFCLASS32 \
? elf_getu32(swap, cap32.c_tag) \
: elf_getu64(swap, cap64.c_tag))
#define xcap_val (clazz == ELFCLASS32 \
? elf_getu32(swap, cap32.c_un.c_val) \
: elf_getu64(swap, cap64.c_un.c_val))
+
#define xauxv_addr (clazz == ELFCLASS32 \
- ? (void *)&auxv32 \
- : (void *)&auxv64)
+ ? CAST(void *, &auxv32) \
+ : CAST(void *, &auxv64))
#define xauxv_sizeof (clazz == ELFCLASS32 \
? sizeof(auxv32) \
: sizeof(auxv64))
@@ -231,6 +243,10 @@ getu64(int swap, uint64_t value)
? elf_getu32(swap, auxv32.a_v) \
: elf_getu64(swap, auxv64.a_v))
+#define prpsoffsets(i) (clazz == ELFCLASS32 \
+ ? prpsoffsets32[i] \
+ : prpsoffsets64[i])
+
#ifdef ELFCORE
/*
* Try larger offsets first to avoid false matches
@@ -269,8 +285,8 @@ static const size_t prpsoffsets64[] = {
16, /* FreeBSD, 64-bit */
};
-#define NOFFSETS32 (sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
-#define NOFFSETS64 (sizeof prpsoffsets64 / sizeof prpsoffsets64[0])
+#define NOFFSETS32 (sizeof(prpsoffsets32) / sizeof(prpsoffsets32[0]))
+#define NOFFSETS64 (sizeof(prpsoffsets64) / sizeof(prpsoffsets64[0]))
#define NOFFSETS (clazz == ELFCLASS32 ? NOFFSETS32 : NOFFSETS64)
@@ -349,7 +365,8 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
* Loop through all the program headers.
*/
for ( ; num; num--) {
- if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
+ if (pread(fd, xph_addr, xph_sizeof, off) <
+ CAST(ssize_t, xph_sizeof)) {
file_badread(ms);
return -1;
}
@@ -392,7 +409,7 @@ static void
do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
{
uint32_t desc;
- (void)memcpy(&desc, v, sizeof(desc));
+ memcpy(&desc, v, sizeof(desc));
desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for NetBSD") == -1)
@@ -438,7 +455,7 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
{
uint32_t desc;
- (void)memcpy(&desc, v, sizeof(desc));
+ memcpy(&desc, v, sizeof(desc));
desc = elf_getu32(swap, desc);
if (file_printf(ms, ", for FreeBSD") == -1)
return;
@@ -536,7 +553,7 @@ do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
if (file_printf(ms, ", BuildID[%s]=", btype) == -1)
return 1;
- (void)memcpy(desc, &nbuf[doff], descsz);
+ memcpy(desc, &nbuf[doff], descsz);
for (i = 0; i < descsz; i++)
if (file_printf(ms, "%02x", desc[i]) == -1)
return 1;
@@ -560,7 +577,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
type == NT_GNU_VERSION && descsz == 16) {
uint32_t desc[4];
- (void)memcpy(desc, &nbuf[doff], sizeof(desc));
+ memcpy(desc, &nbuf[doff], sizeof(desc));
*flags |= FLAGS_DID_OS_NOTE;
if (file_printf(ms, ", for GNU/") == -1)
@@ -627,7 +644,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
*flags |= FLAGS_DID_OS_NOTE;
if (file_printf(ms, ", for DragonFly") == -1)
return 1;
- (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
+ memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
if (file_printf(ms, " %d.%d.%d", desc / 100000,
desc / 10000 % 10, desc % 10000) == -1)
@@ -657,7 +674,7 @@ do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
int did = 0;
*flags |= FLAGS_DID_NETBSD_PAX;
- (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
+ memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
if (desc && file_printf(ms, ", PaX: ") == -1)
@@ -957,7 +974,7 @@ do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
nval = 0;
for (size_t off = 0; off + elsize <= descsz; off += elsize) {
- (void)memcpy(xauxv_addr, &nbuf[doff + off], xauxv_sizeof);
+ memcpy(xauxv_addr, &nbuf[doff + off], xauxv_sizeof);
/* Limit processing to 50 vector entries to prevent DoS */
if (nval++ >= 50) {
file_error(ms, 0, "Too many ELF Auxv elements");
@@ -1021,6 +1038,38 @@ do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
#endif
}
+private size_t
+dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
+ int clazz, int swap)
+{
+ Elf32_Dyn dh32;
+ Elf64_Dyn dh64;
+ unsigned char *dbuf = CAST(unsigned char *, vbuf);
+
+ if (xdh_sizeof + offset > size) {
+ /*
+ * We're out of note headers.
+ */
+ return xdh_sizeof + offset;
+ }
+
+ memcpy(xdh_addr, &dbuf[offset], xdh_sizeof);
+ offset += xdh_sizeof;
+
+ switch (xdh_tag) {
+ case DT_FLAGS_1:
+ if (xdh_val == DF_1_PIE)
+ ms->mode |= 0111;
+ else
+ ms->mode &= ~0111;
+ break;
+ default:
+ break;
+ }
+ return offset;
+}
+
+
private size_t
donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
int clazz, int swap, size_t align, int *flags, uint16_t *notecount,
@@ -1043,7 +1092,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
return xnh_sizeof + offset;
}
- (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
+ memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
offset += xnh_sizeof;
namesz = xnh_namesz;
@@ -1057,14 +1106,14 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
}
if (namesz & 0x80000000) {
- (void)file_printf(ms, ", bad note name size %#lx",
- (unsigned long)namesz);
+ file_printf(ms, ", bad note name size %#lx",
+ CAST(unsigned long, namesz));
return 0;
}
if (descsz & 0x80000000) {
- (void)file_printf(ms, ", bad note description size %#lx",
- (unsigned long)descsz);
+ file_printf(ms, ", bad note description size %#lx",
+ CAST(unsigned long, descsz));
return 0;
}
@@ -1118,35 +1167,25 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
return offset;
}
- if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {
+ if (namesz == 7 && strcmp(CAST(char *, &nbuf[noff]), "NetBSD") == 0) {
+ int descw, flag;
+ const char *str, *tag;
if (descsz > 100)
descsz = 100;
switch (xnh_type) {
case NT_NETBSD_VERSION:
return offset;
case NT_NETBSD_MARCH:
- if (*flags & FLAGS_DID_NETBSD_MARCH)
- return offset;
- *flags |= FLAGS_DID_NETBSD_MARCH;
- if (file_printf(ms, ", compiled for: %.*s",
- (int)descsz, (const char *)&nbuf[doff]) == -1)
- return offset;
+ flag = FLAGS_DID_NETBSD_MARCH;
+ tag = "compiled for";
break;
case NT_NETBSD_CMODEL:
- if (*flags & FLAGS_DID_NETBSD_CMODEL)
- return offset;
- *flags |= FLAGS_DID_NETBSD_CMODEL;
- if (file_printf(ms, ", compiler model: %.*s",
- (int)descsz, (const char *)&nbuf[doff]) == -1)
- return offset;
+ flag = FLAGS_DID_NETBSD_CMODEL;
+ tag = "compiler model";
break;
case NT_NETBSD_EMULATION:
- if (*flags & FLAGS_DID_NETBSD_EMULATION)
- return offset;
- *flags |= FLAGS_DID_NETBSD_EMULATION;
- if (file_printf(ms, ", emulation: %.*s",
- (int)descsz, (const char *)&nbuf[doff]) == -1)
- return offset;
+ flag = FLAGS_DID_NETBSD_EMULATION;
+ tag = "emulation:";
break;
default:
if (*flags & FLAGS_DID_NETBSD_UNKNOWN)
@@ -1154,8 +1193,15 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
*flags |= FLAGS_DID_NETBSD_UNKNOWN;
if (file_printf(ms, ", note=%u", xnh_type) == -1)
return offset;
- break;
+ return offset;
}
+
+ if (*flags & flag)
+ return offset;
+ str = CAST(const char *, &nbuf[doff]);
+ descw = CAST(int, descsz);
+ *flags |= flag;
+ file_printf(ms, ", %s: %.*s", tag, descw, str);
return offset;
}
@@ -1236,7 +1282,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
/* Read offset of name section to be able to read section names later */
if (pread(fd, xsh_addr, xsh_sizeof, CAST(off_t, (off + size * strtab)))
- < (ssize_t)xsh_sizeof) {
+ < CAST(ssize_t, xsh_sizeof)) {
if (file_printf(ms, ", missing section headers") == -1)
return -1;
return 0;
@@ -1245,7 +1291,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
for ( ; num; num--) {
/* Read the name of this section. */
- if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {
+ if ((namesize = pread(fd, name, sizeof(name) - 1,
+ name_off + xsh_name)) == -1) {
file_badread(ms);
return -1;
}
@@ -1255,7 +1302,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
stripped = 0;
}
- if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
+ if (pread(fd, xsh_addr, xsh_sizeof, off) <
+ CAST(ssize_t, xsh_sizeof)) {
file_badread(ms);
return -1;
}
@@ -1281,14 +1329,15 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
/* Things we can determine when we seek */
switch (xsh_type) {
case SHT_NOTE:
- if ((uintmax_t)(xsh_size + xsh_offset) >
- (uintmax_t)fsize) {
+ if (CAST(uintmax_t, (xsh_size + xsh_offset)) >
+ CAST(uintmax_t, fsize)) {
if (file_printf(ms,
", note offset/size %#" INTMAX_T_FORMAT
"x+%#" INTMAX_T_FORMAT "x exceeds"
" file size %#" INTMAX_T_FORMAT "x",
- (uintmax_t)xsh_offset, (uintmax_t)xsh_size,
- (uintmax_t)fsize) == -1)
+ CAST(uintmax_t, xsh_offset),
+ CAST(uintmax_t, xsh_size),
+ CAST(uintmax_t, fsize)) == -1)
return -1;
return 0;
}
@@ -1298,7 +1347,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
return -1;
}
if (pread(fd, nbuf, xsh_size, xsh_offset) <
- (ssize_t)xsh_size) {
+ CAST(ssize_t, xsh_size)) {
file_badread(ms);
free(nbuf);
return -1;
@@ -1306,9 +1355,9 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
noff = 0;
for (;;) {
- if (noff >= (off_t)xsh_size)
+ if (noff >= CAST(off_t, xsh_size))
break;
- noff = donote(ms, nbuf, (size_t)noff,
+ noff = donote(ms, nbuf, CAST(size_t, noff),
xsh_size, clazz, swap, 4, flags, notecount,
fd, 0, 0, 0);
if (noff == 0)
@@ -1330,7 +1379,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
if (nbadcap > 5)
break;
- if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
+ if (lseek(fd, xsh_offset, SEEK_SET)
+ == CAST(off_t, -1)) {
file_badseek(ms);
return -1;
}
@@ -1339,11 +1389,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
Elf32_Cap cap32;
Elf64_Cap cap64;
char cbuf[/*CONSTCOND*/
- MAX(sizeof cap32, sizeof cap64)];
- if ((coff += xcap_sizeof) > (off_t)xsh_size)
+ MAX(sizeof(cap32), sizeof(cap64))];
+ if ((coff += xcap_sizeof) >
+ CAST(off_t, xsh_size))
break;
- if (read(fd, cbuf, (size_t)xcap_sizeof) !=
- (ssize_t)xcap_sizeof) {
+ if (read(fd, cbuf, CAST(size_t, xcap_sizeof)) !=
+ CAST(ssize_t, xcap_sizeof)) {
file_badread(ms);
return -1;
}
@@ -1377,7 +1428,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
#endif
break;
}
- (void)memcpy(xcap_addr, cbuf, xcap_sizeof);
+ memcpy(xcap_addr, cbuf, xcap_sizeof);
switch (xcap_tag) {
case CA_SUNW_NULL:
break;
@@ -1392,8 +1443,9 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
", with unknown capability "
"%#" INT64_T_FORMAT "x = %#"
INT64_T_FORMAT "x",
- (unsigned long long)xcap_tag,
- (unsigned long long)xcap_val) == -1)
+ CAST(unsigned long long, xcap_tag),
+ CAST(unsigned long long, xcap_val))
+ == -1)
return -1;
if (nbadcap++ > 2)
coff = xsh_size;
@@ -1446,12 +1498,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
if (file_printf(ms,
" unknown hardware capability %#"
INT64_T_FORMAT "x",
- (unsigned long long)cap_hw1) == -1)
+ CAST(unsigned long long, cap_hw1)) == -1)
return -1;
} else {
if (file_printf(ms,
" hardware capability %#" INT64_T_FORMAT "x",
- (unsigned long long)cap_hw1) == -1)
+ CAST(unsigned long long, cap_hw1)) == -1)
return -1;
}
}
@@ -1468,7 +1520,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
if (file_printf(ms,
", with unknown software capability %#"
INT64_T_FORMAT "x",
- (unsigned long long)cap_sf1) == -1)
+ CAST(unsigned long long, cap_sf1)) == -1)
return -1;
}
return 0;
@@ -1487,9 +1539,9 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
Elf32_Phdr ph32;
Elf64_Phdr ph64;
const char *linking_style = "statically";
- const char *interp = "";
unsigned char nbuf[BUFSIZ];
char ibuf[BUFSIZ];
+ char interp[BUFSIZ];
ssize_t bufsize;
size_t offset, align, len;
@@ -1499,8 +1551,11 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
return 0;
}
+ interp[0] = '\0';
for ( ; num; num--) {
- if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
+ int doread;
+ if (pread(fd, xph_addr, xph_sizeof, off) <
+ CAST(ssize_t, xph_sizeof)) {
file_badread(ms);
return -1;
}
@@ -1513,6 +1568,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
switch (xph_type) {
case PT_DYNAMIC:
linking_style = "dynamically";
+ doread = 1;
break;
case PT_NOTE:
if (sh_num) /* Did this through section headers */
@@ -1521,21 +1577,16 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
align < 4) {
if (file_printf(ms,
", invalid note alignment %#lx",
- (unsigned long)align) == -1)
+ CAST(unsigned long, align)) == -1)
return -1;
align = 4;
}
/*FALLTHROUGH*/
case PT_INTERP:
- len = xph_filesz < sizeof(nbuf) ? xph_filesz
- : sizeof(nbuf);
- bufsize = pread(fd, nbuf, len, xph_offset);
- if (bufsize == -1) {
- file_badread(ms);
- return -1;
- }
+ doread = 1;
break;
default:
+ doread = 0;
if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
/* Maybe warn here? */
continue;
@@ -1543,14 +1594,39 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
break;
}
+ if (doread) {
+ len = xph_filesz < sizeof(nbuf) ? xph_filesz
+ : sizeof(nbuf);
+ bufsize = pread(fd, nbuf, len, xph_offset);
+ if (bufsize == -1) {
+ file_badread(ms);
+ return -1;
+ }
+ } else
+ len = 0;
+
/* Things we can determine when we seek */
switch (xph_type) {
+ case PT_DYNAMIC:
+ offset = 0;
+ for (;;) {
+ if (offset >= (size_t)bufsize)
+ break;
+ offset = dodynamic(ms, nbuf, offset,
+ CAST(size_t, bufsize), clazz, swap);
+ if (offset == 0)
+ break;
+ }
+ if (ms->flags & MAGIC_MIME)
+ continue;
+ break;
+
case PT_INTERP:
if (bufsize && nbuf[0]) {
nbuf[bufsize - 1] = '\0';
- interp = (const char *)nbuf;
+ memcpy(interp, nbuf, bufsize);
} else
- interp = "*empty*";
+ strlcpy(interp, "*empty*", sizeof(interp));
break;
case PT_NOTE:
/*
@@ -1562,7 +1638,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
if (offset >= (size_t)bufsize)
break;
offset = donote(ms, nbuf, offset,
- (size_t)bufsize, clazz, swap, align,
+ CAST(size_t, bufsize), clazz, swap, align,
flags, notecount, fd, 0, 0, 0);
if (offset == 0)
break;
@@ -1591,7 +1667,7 @@ file_tryelf(struct magic_set *ms, const struct buffer *b)
size_t nbytes = b->flen;
union {
int32_t l;
- char c[sizeof (int32_t)];
+ char c[sizeof(int32_t)];
} u;
int clazz;
int swap;
@@ -1619,7 +1695,8 @@ file_tryelf(struct magic_set *ms, const struct buffer *b)
/*
* If we cannot seek, it must be a pipe, socket or fifo.
*/
- if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
+ if((lseek(fd, CAST(off_t, 0), SEEK_SET) == CAST(off_t, -1))
+ && (errno == ESPIPE))
fd = file_pipe2file(ms, fd, buf, nbytes);
if (fstat(fd, &st) == -1) {
diff --git a/src/readelf.h b/src/readelf.h
index ef880b9..f2f3dc3 100644
--- a/src/readelf.h
+++ b/src/readelf.h
@@ -430,4 +430,107 @@ typedef struct {
#define AV_386_SSE4_1 0x00800000
#define AV_386_SSE4_2 0x01000000
+/*
+ * Dynamic Section structure array
+ */
+typedef struct {
+ Elf32_Word d_tag; /* entry tag value */
+ union {
+ Elf32_Addr d_ptr;
+ Elf32_Word d_val;
+ } d_un;
+} Elf32_Dyn;
+
+typedef struct {
+ Elf64_Xword d_tag; /* entry tag value */
+ union {
+ Elf64_Addr d_ptr;
+ Elf64_Xword d_val;
+ } d_un;
+} Elf64_Dyn;
+
+/* d_tag */
+#define DT_NULL 0 /* Marks end of dynamic array */
+#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
+#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
+#define DT_PLTGOT 3 /* Address of PLT and/or GOT */
+#define DT_HASH 4 /* Address of symbol hash table */
+#define DT_STRTAB 5 /* Address of string table */
+#define DT_SYMTAB 6 /* Address of symbol table */
+#define DT_RELA 7 /* Address of Rela relocation table */
+#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
+#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
+#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
+#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
+#define DT_INIT 12 /* Address of initialization function */
+#define DT_FINI 13 /* Address of termination function */
+#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
+#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
+#define DT_SYMBOLIC 16 /* Start symbol search within local object */
+#define DT_REL 17 /* Address of Rel relocation table */
+#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
+#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
+#define DT_PLTREL 20 /* Type of PLT relocation entries */
+#define DT_DEBUG 21 /* Used for debugging; unspecified */
+#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
+#define DT_JMPREL 23 /* Address of relocations associated with PLT */
+#define DT_BIND_NOW 24 /* Process all relocations at load-time */
+#define DT_INIT_ARRAY 25 /* Address of initialization function array */
+#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
+#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
+#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
+#define DT_RUNPATH 29 /* overrides DT_RPATH */
+#define DT_FLAGS 30 /* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
+#define DT_ENCODING 31 /* ??? */
+#define DT_PREINIT_ARRAY 32 /* Address of pre-init function array */
+#define DT_PREINIT_ARRAYSZ 33 /* Size, in bytes, of DT_PREINIT_ARRAY array */
+#define DT_NUM 34
+
+#define DT_LOOS 0x60000000 /* Operating system specific range */
+#define DT_VERSYM 0x6ffffff0 /* Symbol versions */
+#define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */
+#define DT_VERDEF 0x6ffffffc /* Versions defined by file */
+#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
+#define DT_VERNEED 0x6ffffffe /* Versions needed by file */
+#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
+#define DT_HIOS 0x6fffffff
+#define DT_LOPROC 0x70000000 /* Processor-specific range */
+#define DT_HIPROC 0x7fffffff
+
+/* Flag values for DT_FLAGS */
+#define DF_ORIGIN 0x00000001 /* uses $ORIGIN */
+#define DF_SYMBOLIC 0x00000002 /* */
+#define DF_TEXTREL 0x00000004 /* */
+#define DF_BIND_NOW 0x00000008 /* */
+#define DF_STATIC_TLS 0x00000010 /* */
+
+/* Flag values for DT_FLAGS_1 */
+#define DF_1_NOW 0x00000001 /* Same as DF_BIND_NOW */
+#define DF_1_GLOBAL 0x00000002 /* Unused */
+#define DF_1_GROUP 0x00000004 /* Is member of group */
+#define DF_1_NODELETE 0x00000008 /* Cannot be deleted from process */
+#define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filters */
+#define DF_1_INITFIRST 0x00000020 /* init/fini takes priority */
+#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */
+#define DF_1_ORIGIN 0x00000080 /* Require $ORIGIN processing */
+#define DF_1_DIRECT 0x00000100 /* Enable direct bindings */
+#define DF_1_INTERPOSE 0x00000400 /* Is an interposer */
+#define DF_1_NODEFLIB 0x00000800 /* Ignore default library search path */
+#define DF_1_NODUMP 0x00001000 /* Cannot be dumped with dldump(3C) */
+#define DF_1_CONFALT 0x00002000 /* Configuration alternative */
+#define DF_1_ENDFILTEE 0x00004000 /* Filtee ends filter's search */
+#define DF_1_DISPRELDNE 0x00008000 /* Did displacement relocation */
+#define DF_1_DISPRELPND 0x00010000 /* Pending displacement relocation */
+#define DF_1_NODIRECT 0x00020000 /* Has non-direct bindings */
+#define DF_1_IGNMULDEF 0x00040000 /* Used internally */
+#define DF_1_NOKSYMS 0x00080000 /* Used internally */
+#define DF_1_NOHDR 0x00100000 /* Used internally */
+#define DF_1_EDITED 0x00200000 /* Has been modified since build */
+#define DF_1_NORELOC 0x00400000 /* Used internally */
+#define DF_1_SYMINTPOSE 0x00800000 /* Has individual symbol interposers */
+#define DF_1_GLOBAUDIT 0x01000000 /* Require global auditing */
+#define DF_1_SINGLETON 0x02000000 /* Has singleton symbols */
+#define DF_1_STUB 0x04000000 /* Stub */
+#define DF_1_PIE 0x08000000 /* Position Independent Executable */
+
#endif
--
2.39.1

@ -1,68 +0,0 @@
From f8ba1437114e408de0f66efb272fdc1de986017a Mon Sep 17 00:00:00 2001
From: Vincent Mihalkovic <vmihalko@redhat.com>
Date: Mon, 6 Feb 2023 14:39:58 +0100
Subject: [PATCH] We need to process the dynamic section so that we can set $x
for mime.
9ffbd485ba4647827c4bdacf3a2de690f6765b0c
---
src/readelf.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index cdc211f..94cdaca 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1273,6 +1273,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilities */
char name[50];
ssize_t namesize;
+ if (ms->flags & MAGIC_MIME)
+ return 0;
if (size != xsh_sizeof) {
if (file_printf(ms, ", corrupted section header size") == -1)
@@ -1622,6 +1624,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
break;
case PT_INTERP:
+ if (ms->flags & MAGIC_MIME)
+ continue;
if (bufsize && nbuf[0]) {
nbuf[bufsize - 1] = '\0';
memcpy(interp, nbuf, bufsize);
@@ -1629,6 +1633,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
strlcpy(interp, "*empty*", sizeof(interp));
break;
case PT_NOTE:
+ if (ms->flags & MAGIC_MIME)
+ return 0;
/*
* This is a PT_NOTE section; loop through all the notes
* in the section.
@@ -1645,9 +1651,13 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
break;
default:
+ if (ms->flags & MAGIC_MIME)
+ continue;
break;
}
}
+ if (ms->flags & MAGIC_MIME)
+ return 0;
if (file_printf(ms, ", %s linked", linking_style)
== -1)
return -1;
@@ -1678,7 +1688,7 @@ file_tryelf(struct magic_set *ms, const struct buffer *b)
Elf64_Ehdr elf64hdr;
uint16_t type, phnum, shnum, notecount;
- if (ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION))
+ if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
return 0;
/*
* ELF executables have multiple section headers in arbitrary
--
2.39.1

@ -1,36 +0,0 @@
From 27c951adbd5d7ebe95f08c18257ea031bdd59ee1 Mon Sep 17 00:00:00 2001
From: Vincent Mihalkovic <vmihalko@redhat.com>
Date: Mon, 6 Feb 2023 15:00:16 +0100
Subject: [PATCH] For dynamic binaries let the df_1 pie flag determine if we
are pie or a shared object, and ignore the mode bits.
upstream commit: 03084b161cf888b5286dbbcd964c31ccad4f64d9
---
src/readelf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 94cdaca..9c75c0a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1058,7 +1058,7 @@ dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
switch (xdh_tag) {
case DT_FLAGS_1:
- if (xdh_val == DF_1_PIE)
+ if (xdh_val & DF_1_PIE)
ms->mode |= 0111;
else
ms->mode &= ~0111;
@@ -1611,6 +1611,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
switch (xph_type) {
case PT_DYNAMIC:
offset = 0;
+ // Let DF_1 determine if we are PIE or not.
+ ms->mode &= ~0111;
for (;;) {
if (offset >= (size_t)bufsize)
break;
--
2.39.1

@ -1,13 +0,0 @@
diff --git a/src/readelf.c b/src/readelf.c
index d836e68..6d4b40b 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -69,7 +69,7 @@ toomany(struct magic_set *ms, const char *name, uint16_t num)
{
if (file_printf(ms, ", too many %s (%u)", name, num) == -1)
return -1;
- return 0;
+ return 1;
}
private uint16_t

@ -1,49 +0,0 @@
diff --git a/magic/Magdir/measure b/magic/Magdir/measure
index f23c1d6..963d85f 100644
--- a/magic/Magdir/measure
+++ b/magic/Magdir/measure
@@ -8,31 +8,31 @@
>0 beshort x scale %d-
>2 beshort x \b%d,
>4 lefloat x spot sensor temperature %f,
->9 byte 0 unit celsius,
->9 byte 1 unit fahrenheit,
->8 byte x color scheme %d
->10 byte 1 \b, show spot sensor
->11 byte 1 \b, show scale bar
->12 byte &1 \b, minimum point enabled
->12 byte &2 \b, maximum point enabled
+>9 ubyte 0 unit celsius,
+>9 ubyte 1 unit fahrenheit,
+>8 ubyte x color scheme %d
+>10 ubyte 1 \b, show spot sensor
+>11 ubyte 1 \b, show scale bar
+>12 ubyte &1 \b, minimum point enabled
+>12 ubyte &2 \b, maximum point enabled
>13 lefloat x \b, calibration: offset %f,
>17 lefloat x slope %f
0 name diy-thermocam-checker
->9 byte <2
->>10 byte <2
->>>11 byte <2
->>>>12 byte <4
+>9 ubyte <2
+>>10 ubyte <2
+>>>11 ubyte <2
+>>>>12 ubyte <4
>>>>>17 lefloat >0.0001 DIY-Thermocam raw data
# V2 and Leption 3.x:
-38408 byte <19
+38408 ubyte <19
>38400 use diy-thermocam-checker
>>38400 default x (Lepton 3.x),
>>>38400 use diy-thermocam-parser
# V1 or Lepton 2.x
-9608 byte <19
+9608 ubyte <19
>9600 use diy-thermocam-checker
>>9600 default x (Lepton 2.x),
>>>9600 use diy-thermocam-parser

@ -1,14 +0,0 @@
diff -urp file-5.33.orig/src/softmagic.c file-5.33/src/softmagic.c
--- file-5.33.orig/src/softmagic.c 2018-04-15 14:49:15.000000000 -0400
+++ file-5.33/src/softmagic.c 2020-12-14 12:21:13.298285158 -0500
@@ -1758,7 +1758,9 @@ file_strncmp(const char *s1, const char
*/
const unsigned char *a = (const unsigned char *)s1;
const unsigned char *b = (const unsigned char *)s2;
- const unsigned char *eb = b + len;
+ uint32_t ws = flags & (STRING_COMPACT_WHITESPACE |
+ STRING_COMPACT_OPTIONAL_WHITESPACE);
+ const unsigned char *eb = b + (ws ? strlen(s2) : len);
uint64_t v;
/*

@ -1,26 +0,0 @@
From b675e1cf6c5f047a1ab52b7dcea3c83ea6aac69f Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Fri, 9 Nov 2018 17:51:12 +0000
Subject: [PATCH] Add eBPF magic from Matteo Croce
Upstream-commit: 4cf4e817457ce6ca32452a7c80b27e96be6441dc
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/elf | 1 +
1 file changed, 1 insertion(+)
diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index 133bd1f..7c6011c 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -263,6 +263,7 @@
>18 leshort 217 iCelero CoolEngine,
>18 leshort 218 Nanoradio Optimized RISC,
>18 leshort 243 UCB RISC-V,
+>18 leshort 247 eBPF,
>18 leshort 0x1057 AVR (unofficial),
>18 leshort 0x1059 MSP430 (unofficial),
>18 leshort 0x1223 Adapteva Epiphany (unofficial),
--
2.17.2

@ -1,56 +0,0 @@
From 5bccda402a33b4b6fee13cbc910580a85f1ab73a Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 18 Feb 2019 18:59:25 +0000
Subject: [PATCH 1/2] Mention that the apple filetype/creator is only available for
entries that have it (Kamil Dudka)
Upstream-commit: 642f269ef99930b44daa2236908da7d05a68eb08
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
doc/file.man | 3 +++
1 file changed, 3 insertions(+)
diff --git a/doc/file.man b/doc/file.man
index 0968321..98061ba 100644
--- a/doc/file.man
+++ b/doc/file.man
@@ -171,6 +171,9 @@ Causes the file command to output the file type and creator code as
used by older MacOS versions.
The code consists of eight letters,
the first describing the file type, the latter the creator.
+the first describing the file type, the latter the creator.
+This option works properly only for file formats that have the
+apple-style output defined.
.It Fl b , Fl Fl brief
Do not prepend filenames to output lines (brief mode).
.It Fl C , Fl Fl compile
--
2.20.1
From f7f3e751c0e606592b4d377a479b40f6964705ab Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sun, 3 Mar 2019 02:32:40 +0000
Subject: [PATCH 2/2] remove duplicate line (chefe)
Upstream-commit: cde5f5962ebfd057fc2e330da3b36470e6ee3724
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
doc/file.man | 1 -
1 file changed, 1 deletion(-)
diff --git a/doc/file.man b/doc/file.man
index 98061ba..05da3a7 100644
--- a/doc/file.man
+++ b/doc/file.man
@@ -171,7 +171,6 @@ Causes the file command to output the file type and creator code as
used by older MacOS versions.
The code consists of eight letters,
the first describing the file type, the latter the creator.
-the first describing the file type, the latter the creator.
This option works properly only for file formats that have the
apple-style output defined.
.It Fl b , Fl Fl brief
--
2.21.1

@ -1,67 +0,0 @@
From b3842fb61c829b0b62e7b8a058b8a86cd83aa0e7 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Tue, 22 Jan 2019 16:17:25 +0000
Subject: [PATCH] Make netpbm beat DOS/MBR magic again (Kamil Dudka)
Upstream-commit: d2f82e2601e551badc03c4ac7a463d8e18f53e32
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/images | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/magic/Magdir/images b/magic/Magdir/images
index fd20261..afe906c 100644
--- a/magic/Magdir/images
+++ b/magic/Magdir/images
@@ -175,42 +175,42 @@
>0 regex/4 P1[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, bitmap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-bitmap
0 search/1 P2
>0 regex/4 P2[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, greymap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-greymap
0 search/1 P3
>0 regex/4 P3[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, pixmap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-pixmap
0 string P4
>0 regex/4 P4[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, rawbits, bitmap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-bitmap
0 string P5
>0 regex/4 P5[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, rawbits, greymap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-greymap
0 string P6
>0 regex/4 P6[\040\t\f\r\n]
>>0 use netpbm
>>>0 string x \b, rawbits, pixmap
-!:strength + 45
+!:strength + 65
!:mime image/x-portable-pixmap
0 string P7 Netpbm PAM image file
--
2.20.1

@ -1,62 +0,0 @@
From 7a4b49897c3bc63bdf680f8cb1d7a04ac932a4ff Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 21 May 2018 16:32:34 +0000
Subject: [PATCH 1/2] Add missing commas.
Upstream-commit: defcf7e39943780dd19ca002c478e52ec9ee5cbc
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/elf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/magic/Magdir/elf b/magic/Magdir/elf
index 7c6ac8f..d5b2d02 100644
--- a/magic/Magdir/elf
+++ b/magic/Magdir/elf
@@ -50,7 +50,7 @@
!:mime application/x-executable
>16 leshort 3 shared object,
!:mime application/x-sharedlib
->16 leshort 4 core file
+>16 leshort 4 core file,
!:mime application/x-coredump
# Core file detection is not reliable.
#>>>(0x38+0xcc) string >\0 of '%s'
--
2.20.1
From 1c7aa7b88ef9f53e19a64961867427b0c1f04857 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Tue, 22 Jan 2019 16:28:42 +0000
Subject: [PATCH 2/2] Add Linux PowerPC core offsets for Linux (which are off-by-4
of the regular offsets), after the regular Linux offsets so that there is no
confusion. The linux offsets are tried first since they are before, so on PPC
they should contain binary data and not match. Addition requested by: Ondrej
Dubaj/Kamil Dudka
Upstream-commit: 6367a7c9b476767a692f76e78e3b355dc9386e48
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/readelf.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index d96a538..c101483 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -246,7 +246,10 @@ static const size_t prpsoffsets32[] = {
84, /* SunOS 5.x (short name) */
44, /* Linux (command line) */
- 28, /* Linux 2.0.36 (short name) */
+ 28, /* Linux (short name) */
+
+ 48, /* Linux PowerPC (command line) */
+ 32, /* Linux PowerPC (short name) */
8, /* FreeBSD */
};
--
2.20.1

@ -1,52 +0,0 @@
From f73ad90e797824569008a054bea6c8215883a3a0 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 26 Aug 2019 14:31:39 +0000
Subject: [PATCH] Limit the number of elements in a vector (found by oss-fuzz)
Upstream-commit: 46a8443f76cec4b41ec736eca396984c74664f84
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/cdf.c | 7 +++----
src/cdf.h | 1 +
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cdf.c b/src/cdf.c
index 556a3ff..8bb0a6d 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -1013,8 +1013,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
goto out;
}
nelements = CDF_GETUINT32(q, 1);
- if (nelements == 0) {
- DPRINTF(("CDF_VECTOR with nelements == 0\n"));
+ if (nelements > CDF_ELEMENT_LIMIT || nelements == 0) {
+ DPRINTF(("CDF_VECTOR with nelements == %"
+ SIZE_T_FORMAT "u\n", nelements));
goto out;
}
slen = 2;
@@ -1056,8 +1057,6 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
goto out;
inp += nelem;
}
- DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
- nelements));
for (j = 0; j < nelements && i < sh.sh_properties;
j++, i++)
{
diff --git a/src/cdf.h b/src/cdf.h
index 2f7e554..0505666 100644
--- a/src/cdf.h
+++ b/src/cdf.h
@@ -48,6 +48,7 @@
typedef int32_t cdf_secid_t;
#define CDF_LOOP_LIMIT 10000
+#define CDF_ELEMENT_LIMIT 100000
#define CDF_SECID_NULL 0
#define CDF_SECID_FREE -1
--
2.20.1

@ -1,40 +0,0 @@
From 432267e707aca36bec55704fd404fa572e2c4b45 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Fri, 15 Nov 2019 23:49:38 +0000
Subject: [PATCH] fix JFFS2 (the old magic was just hex encoded 0x1984 which is
wrong (Kamil Dudka)
Upstream-commit: 5ad78c726bb03e0fbdb6d237ef2b13e51968ffea
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/Magdir/filesystems | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
index 1920e56..da5c580 100644
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
@@ -2057,10 +2057,6 @@
>0x10040 lelong 2 yura hash
>0x10040 lelong 3 r5 hash
-# JFFS - russell@coker.com.au
-0 lelong 0x34383931 Linux Journalled Flash File system, little endian
-0 belong 0x34383931 Linux Journalled Flash File system, big endian
-
# EST flat binary format (which isn't, but anyway)
# From: Mark Brown <broonie@sirena.org.uk>
0 string ESTFBINR EST flat binary
@@ -2144,7 +2140,9 @@
# JFFS2 file system
0 leshort 0x1984 Linux old jffs2 filesystem data little endian
+0 beshort 0x1984 Linux old jffs2 filesystem data big endian
0 leshort 0x1985 Linux jffs2 filesystem data little endian
+0 beshort 0x1985 Linux jffs2 filesystem data big endian
# Squashfs
0 string sqsh Squashfs filesystem, big endian,
--
2.20.1

@ -0,0 +1,201 @@
diff --git a/ChangeLog b/ChangeLog
index d46caaa0d..41d6e99d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-12-08 16:24 Christos Zoulas <christos@zoulas.com>
+
+ * fix multithreaded decompression file descriptor issue
+ by using close-on-exec (Denys Vlasenko)
+
2020-06-14 20:02 Christos Zoulas <christos@zoulas.com>
* release 5.39
diff --git a/configure.ac b/configure.ac
index 64c9f42e3..521dc12db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,7 +166,7 @@ else
fi])
dnl Checks for functions
-AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem)
+AC_CHECK_FUNCS(strndup mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale memmem pipe2)
dnl Provide implementation of some required functions if necessary
AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r localtime_r gmtime_r pread strcasestr fmtcheck dprintf)
diff --git a/src/compress.c b/src/compress.c
index cbc2ce19b..9f65e4fa1 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.127 2020/05/31 00:11:06 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.129 2020/12/08 21:26:00 christos Exp $")
#endif
#include "magic.h"
@@ -844,8 +844,23 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
for (i = 0; i < __arraycount(fdp); i++)
fdp[i][0] = fdp[i][1] = -1;
- if ((fd == -1 && pipe(fdp[STDIN_FILENO]) == -1) ||
- pipe(fdp[STDOUT_FILENO]) == -1 || pipe(fdp[STDERR_FILENO]) == -1) {
+ /*
+ * There are multithreaded users who run magic_file()
+ * from dozens of threads. If two parallel 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.
+ * If uncompressed data is larger, child shound get EPIPE and exit.
+ * However, with *parallel* calls OTHER child may unintentionally
+ * inherit pipe fds, thus keeping pipe open and making writes in
+ * our child block instead of failing with EPIPE!
+ * (For the bug to occur, two threads must mutually inherit their pipes,
+ * and both must have large outputs. Thus it happens not that often).
+ * To avoid this, be sure to create pipes with O_CLOEXEC.
+ */
+ if ((fd == -1 && file_pipe_closexec(fdp[STDIN_FILENO]) == -1) ||
+ file_pipe_closexec(fdp[STDOUT_FILENO]) == -1 ||
+ file_pipe_closexec(fdp[STDERR_FILENO]) == -1) {
closep(fdp[STDIN_FILENO]);
closep(fdp[STDOUT_FILENO]);
return makeerror(newch, n, "Cannot create pipe, %s",
@@ -876,16 +891,20 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
if (fdp[STDIN_FILENO][1] > 2)
(void) close(fdp[STDIN_FILENO][1]);
}
+ file_clear_closexec(STDIN_FILENO);
+
///FIXME: if one of the fdp[i][j] is 0 or 1, this can bomb spectacularly
if (copydesc(STDOUT_FILENO, fdp[STDOUT_FILENO][1]))
(void) close(fdp[STDOUT_FILENO][1]);
if (fdp[STDOUT_FILENO][0] > 2)
(void) close(fdp[STDOUT_FILENO][0]);
+ file_clear_closexec(STDOUT_FILENO);
if (copydesc(STDERR_FILENO, fdp[STDERR_FILENO][1]))
(void) close(fdp[STDERR_FILENO][1]);
if (fdp[STDERR_FILENO][0] > 2)
(void) close(fdp[STDERR_FILENO][0]);
+ file_clear_closexec(STDERR_FILENO);
(void)execvp(compr[method].argv[0],
RCAST(char *const *, RCAST(intptr_t, compr[method].argv)));
diff --git a/src/file.h b/src/file.h
index f00e8010b..6c3900479 100644
--- a/src/file.h
+++ b/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.220 2020/06/08 17:38:27 christos Exp $
+ * @(#)$File: file.h,v 1.223 2020/12/08 21:26:00 christos Exp $
*/
#ifndef __file_h__
@@ -143,6 +143,14 @@
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
+
#define FILE_BADSIZE CAST(size_t, ~0ul)
#define MAXDESC 64 /* max len of text description/MIME type */
#define MAXMIME 80 /* max len of text MIME type */
@@ -540,6 +548,8 @@ protected char * file_printable(char *, size_t, const char *, size_t);
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
size_t);
#endif /* __EMX__ */
+protected int file_pipe_closexec(int *);
+protected int file_clear_closexec(int);
protected void buffer_init(struct buffer *, int, const struct stat *,
const void *, size_t);
diff --git a/src/funcs.c b/src/funcs.c
index ecbfa28c5..bcf9ddaae 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.115 2020/02/20 15:50:20 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.118 2020/12/08 21:26:00 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -36,6 +36,9 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.117 2020/06/25 16:52:48 christos Exp $")
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for pipe2() */
+#endif
#if defined(HAVE_WCHAR_H)
#include <wchar.h>
#endif
@@ -784,3 +787,22 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
g->data4[2], g->data4[3], g->data4[4], g->data4[5],
g->data4[6], g->data4[7]);
}
+
+protected int
+file_pipe_closexec(int *fds)
+{
+#ifdef HAVE_PIPE2
+ return pipe2(fds, O_CLOEXEC);
+#else
+ if (pipe(fds) == -1)
+ return -1;
+ (void)fcntl(fds[0], F_SETFD, FD_CLOEXEC);
+ (void)fcntl(fds[1], F_SETFD, FD_CLOEXEC);
+ return 0;
+#endif
+}
+
+protected int
+file_clear_closexec(int fd) {
+ return fcntl(fd, F_SETFD, 0);
+}
diff --git a/src/magic.c b/src/magic.c
index 17a7077d8..89f4e16c0 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -33,7 +33,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.112 2020/06/08 19:44:10 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.113 2020/12/08 21:26:00 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -436,7 +436,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
_setmode(STDIN_FILENO, O_BINARY);
#endif
if (inname != NULL) {
- int flags = O_RDONLY|O_BINARY|O_NONBLOCK;
+ int flags = O_RDONLY|O_BINARY|O_NONBLOCK|O_CLOEXEC;
errno = 0;
if ((fd = open(inname, flags)) < 0) {
okstat = stat(inname, &sb) == 0;
@@ -460,6 +460,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
rv = 0;
goto done;
}
+#if O_CLOEXEC == 0
+ (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
}
if (fd != -1) {

@ -1,5 +1,5 @@
diff --git a/src/Makefile.am b/src/Makefile.am
index a9b245d..c7f184d 100644
index b43cb8e..93d6625 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,10 +17,10 @@ MINGWLIBS = -lgnurx -lshlwapi
@ -16,10 +16,10 @@ index a9b245d..c7f184d 100644
EXTRA_DIST = magic.h.in
HDR= $(top_srcdir)/src/magic.h.in
diff --git a/src/softmagic.c b/src/softmagic.c
index 3e76517..57b4677 100644
index becc53c..39c7e0b 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -37,6 +37,7 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.259 2018/03/11 01:23:52 christos Exp $")
@@ -37,6 +37,7 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.299 2020/06/07 21:58:01 christos Exp $")
#include "magic.h"
#include <assert.h>
@ -27,7 +27,7 @@ index 3e76517..57b4677 100644
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
@@ -1893,19 +1894,19 @@ magiccheck(struct magic_set *ms, struct magic *m)
@@ -2074,19 +2075,19 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
break;
case '!':
@ -51,7 +51,7 @@ index 3e76517..57b4677 100644
break;
default:
@@ -1926,19 +1927,19 @@ magiccheck(struct magic_set *ms, struct magic *m)
@@ -2107,19 +2108,19 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
break;
case '!':

@ -0,0 +1,377 @@
diff --git a/src/apprentice.c b/src/apprentice.c
index b609dd1..21eac1e 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -423,7 +423,15 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
ml->map = idx == 0 ? map : NULL;
ml->magic = map->magic[idx];
ml->nmagic = map->nmagic[idx];
-
+ if (ml->nmagic) {
+ ml->magic_rxcomp = CAST(file_regex_t **,
+ calloc(ml->nmagic, sizeof(*ml->magic_rxcomp)));
+ if (ml->magic_rxcomp == NULL) {
+ free(ml);
+ return -1;
+ }
+ } else
+ ml->magic_rxcomp = NULL;
mlp->prev->next = ml;
ml->prev = mlp->prev;
ml->next = mlp;
@@ -607,8 +615,19 @@ mlist_free_all(struct magic_set *ms)
private void
mlist_free_one(struct mlist *ml)
{
+ size_t i;
+
if (ml->map)
apprentice_unmap(CAST(struct magic_map *, ml->map));
+
+ for (i = 0; i < ml->nmagic; ++i) {
+ if (ml->magic_rxcomp[i]) {
+ file_regfree(ml->magic_rxcomp[i]);
+ free(ml->magic_rxcomp[i]);
+ }
+ }
+ free(ml->magic_rxcomp);
+ ml->magic_rxcomp = NULL;
free(ml);
}
@@ -3492,16 +3511,16 @@ file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
for (ml = mlist->next; ml != mlist; ml = ml->next) {
struct magic *ma = ml->magic;
- uint32_t nma = ml->nmagic;
- for (i = 0; i < nma; i++) {
+ for (i = 0; i < ml->nmagic; i++) {
if (ma[i].type != FILE_NAME)
continue;
if (strcmp(ma[i].value.s, name) == 0) {
v->magic = &ma[i];
- for (j = i + 1; j < nma; j++)
+ for (j = i + 1; j < ml->nmagic; j++)
if (ma[j].cont_level == 0)
break;
v->nmagic = j - i;
+ v->magic_rxcomp = ml->magic_rxcomp;
return 0;
}
}
diff --git a/src/file.h b/src/file.h
index 48f4b69..c0b5a7c 100644
--- a/src/file.h
+++ b/src/file.h
@@ -88,6 +88,10 @@
/* Do this here and now, because struct stat gets re-defined on solaris */
#include <sys/stat.h>
#include <stdarg.h>
+#include <locale.h>
+#if defined(HAVE_XLOCALE_H)
+#include <xlocale.h>
+#endif
#define ENABLE_CONDITIONALS
@@ -167,6 +171,19 @@
#define FILE_COMPILE 2
#define FILE_LIST 3
+typedef struct {
+ const char *pat;
+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
+#define USE_C_LOCALE
+ locale_t old_lc_ctype;
+ locale_t c_lc_ctype;
+#else
+ char *old_lc_ctype;
+#endif
+ int rc;
+ regex_t rx;
+} file_regex_t;
+
struct buffer {
int fd;
struct stat st;
@@ -394,7 +411,8 @@ struct magic {
/* list of magic entries */
struct mlist {
struct magic *magic; /* array of magic entries */
- uint32_t nmagic; /* number of entries in array */
+ file_regex_t **magic_rxcomp; /* array of compiled regexps */
+ size_t nmagic; /* number of entries in array */
void *map; /* internal resources used by entry */
struct mlist *next, *prev;
};
@@ -554,23 +572,7 @@ protected void buffer_init(struct buffer *, int, const struct stat *,
protected void buffer_fini(struct buffer *);
protected int buffer_fill(const struct buffer *);
-#include <locale.h>
-#if defined(HAVE_XLOCALE_H)
-#include <xlocale.h>
-#endif
-typedef struct {
- const char *pat;
-#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
-#define USE_C_LOCALE
- locale_t old_lc_ctype;
- locale_t c_lc_ctype;
-#else
- char *old_lc_ctype;
-#endif
- int rc;
- regex_t rx;
-} file_regex_t;
protected int file_regcomp(file_regex_t *, const char *, int);
protected int file_regexec(file_regex_t *, const char *, size_t, regmatch_t *,
diff --git a/src/softmagic.c b/src/softmagic.c
index 95061e5..834dfe3 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -43,7 +43,7 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.299 2020/06/07 21:58:01 christos Exp $")
#include <time.h>
#include "der.h"
-private int match(struct magic_set *, struct magic *, uint32_t,
+private int match(struct magic_set *, struct magic *, file_regex_t **, uint32_t,
const struct buffer *, size_t, int, int, int, uint16_t *,
uint16_t *, int *, int *, int *, int *);
private int mget(struct magic_set *, struct magic *, const struct buffer *,
@@ -52,7 +52,7 @@ private int mget(struct magic_set *, struct magic *, const struct buffer *,
uint16_t *, int *, int *, int *, int *);
private int msetoffset(struct magic_set *, struct magic *, struct buffer *,
const struct buffer *, size_t, unsigned int);
-private int magiccheck(struct magic_set *, struct magic *);
+private int magiccheck(struct magic_set *, struct magic *, file_regex_t **);
private int32_t mprint(struct magic_set *, struct magic *);
private int moffset(struct magic_set *, struct magic *, const struct buffer *,
int32_t *);
@@ -131,8 +131,8 @@ file_softmagic(struct magic_set *ms, const struct buffer *b,
}
for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
- if ((rv = match(ms, ml->magic, ml->nmagic, b, 0, mode,
- text, 0, indir_count, name_count,
+ if ((rv = match(ms, ml->magic, ml->magic_rxcomp, ml->nmagic, b,
+ 0, mode, text, 0, indir_count, name_count,
&printed_something, &need_separator, NULL, NULL)) != 0)
return rv;
@@ -191,8 +191,8 @@ file_fmtcheck(struct magic_set *ms, const char *desc, const char *def,
* so that higher-level continuations are processed.
*/
private int
-match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
- const struct buffer *b, size_t offset, int mode, int text,
+match(struct magic_set *ms, struct magic *magic, file_regex_t **magic_rxcomp,
+ uint32_t nmagic, const struct buffer *b, size_t offset, int mode, int text,
int flip, uint16_t *indir_count, uint16_t *name_count,
int *printed_something, int *need_separator, int *returnval,
int *found_match)
@@ -220,6 +220,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
for (magindex = 0; magindex < nmagic; magindex++) {
int flush = 0;
struct magic *m = &magic[magindex];
+ file_regex_t **m_rxcomp = &magic_rxcomp[magindex];
if (m->type != FILE_NAME)
if ((IS_STRING(m->type) &&
@@ -257,7 +258,7 @@ flush:
*returnval = 1;
}
- switch (magiccheck(ms, m)) {
+ switch (magiccheck(ms, m, m_rxcomp)) {
case -1:
return -1;
case 0:
@@ -317,6 +318,7 @@ flush:
while (magindex + 1 < nmagic &&
magic[magindex + 1].cont_level != 0) {
m = &magic[++magindex];
+ m_rxcomp = &magic_rxcomp[magindex];
ms->line = m->lineno; /* for messages */
if (cont_level < m->cont_level)
@@ -370,7 +372,7 @@ flush:
break;
}
- switch (flush ? 1 : magiccheck(ms, m)) {
+ switch (flush ? 1 : magiccheck(ms, m, m_rxcomp)) {
case -1:
return -1;
case 0:
@@ -1880,8 +1882,8 @@ mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
oneed_separator = *need_separator;
if (m->flag & NOSPACE)
*need_separator = 0;
- rv = match(ms, ml.magic, ml.nmagic, b, offset + o,
- mode, text, flip, indir_count, name_count,
+ rv = match(ms, ml.magic, ml.magic_rxcomp, ml.nmagic, b,
+ offset + o, mode, text, flip, indir_count, name_count,
printed_something, need_separator, returnval, found_match);
(*name_count)--;
if (rv != 1)
@@ -1989,8 +1991,31 @@ file_strncmp16(const char *a, const char *b, size_t len, size_t maxlen,
return file_strncmp(a, b, len, maxlen, flags);
}
+private file_regex_t *
+alloc_regex(struct magic_set *ms, struct magic *m)
+{
+ int rc;
+ file_regex_t *rx = CAST(file_regex_t *, malloc(sizeof(*rx)));
+
+ if (rx == NULL) {
+ file_error(ms, errno, "can't allocate %" SIZE_T_FORMAT
+ "u bytes", sizeof(*rx));
+ return NULL;
+ }
+
+ rc = file_regcomp(rx, m->value.s, REG_EXTENDED | REG_NEWLINE |
+ ((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0));
+ if (rc == 0)
+ return rx;
+
+ file_regerror(rx, rc, ms);
+ file_regfree(rx);
+ free(rx);
+ return NULL;
+}
+
private int
-magiccheck(struct magic_set *ms, struct magic *m)
+magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
{
uint64_t l = m->value.q;
uint64_t v;
@@ -2068,8 +2093,8 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "cannot happen with float: invalid relation `%c'",
- m->reln);
+ file_magerror(ms, "cannot happen with float: "
+ "invalid relation `%c'", m->reln);
return -1;
}
return matched;
@@ -2101,7 +2126,8 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln);
+ file_magerror(ms, "cannot happen with double: "
+ "invalid relation `%c'", m->reln);
return -1;
}
return matched;
@@ -2169,62 +2195,57 @@ magiccheck(struct magic_set *ms, struct magic *m)
}
case FILE_REGEX: {
int rc;
- file_regex_t rx;
+ file_regex_t *rx = *m_cache;
const char *search;
+ regmatch_t pmatch;
+ size_t slen = ms->search.s_len;
+ char *copy;
if (ms->search.s == NULL)
return 0;
+ if (rx == NULL) {
+ rx = *m_cache = alloc_regex(ms, m);
+ if (rx == NULL)
+ return -1;
+ }
l = 0;
- rc = file_regcomp(&rx, m->value.s,
- REG_EXTENDED|REG_NEWLINE|
- ((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0));
- if (rc) {
- file_regerror(&rx, rc, ms);
- v = CAST(uint64_t, -1);
+ if (slen != 0) {
+ copy = CAST(char *, malloc(slen));
+ if (copy == NULL) {
+ file_error(ms, errno,
+ "can't allocate %" SIZE_T_FORMAT "u bytes",
+ slen);
+ return -1;
+ }
+ memcpy(copy, ms->search.s, slen);
+ copy[--slen] = '\0';
+ search = copy;
} else {
- regmatch_t pmatch;
- size_t slen = ms->search.s_len;
- char *copy;
- if (slen != 0) {
- copy = CAST(char *, malloc(slen));
- if (copy == NULL) {
- file_regfree(&rx);
- file_error(ms, errno,
- "can't allocate %" SIZE_T_FORMAT "u bytes",
- slen);
- return -1;
- }
- memcpy(copy, ms->search.s, slen);
- copy[--slen] = '\0';
- search = copy;
- } else {
- search = CCAST(char *, "");
- copy = NULL;
- }
- rc = file_regexec(&rx, RCAST(const char *, search),
- 1, &pmatch, 0);
- free(copy);
- switch (rc) {
- case 0:
- ms->search.s += CAST(int, pmatch.rm_so);
- ms->search.offset += CAST(size_t, pmatch.rm_so);
- ms->search.rm_len = CAST(size_t,
- pmatch.rm_eo - pmatch.rm_so);
- v = 0;
- break;
+ search = CCAST(char *, "");
+ copy = NULL;
+ }
+ rc = file_regexec(rx, RCAST(const char *, search),
+ 1, &pmatch, 0);
+ free(copy);
+ switch (rc) {
+ case 0:
+ ms->search.s += CAST(int, pmatch.rm_so);
+ ms->search.offset += CAST(size_t, pmatch.rm_so);
+ ms->search.rm_len = CAST(size_t,
+ pmatch.rm_eo - pmatch.rm_so);
+ v = 0;
+ break;
- case REG_NOMATCH:
- v = 1;
- break;
+ case REG_NOMATCH:
+ v = 1;
+ break;
- default:
- file_regerror(&rx, rc, ms);
- v = CAST(uint64_t, -1);
- break;
- }
+ default:
+ file_regerror(rx, rc, ms);
+ v = CAST(uint64_t, -1);
+ break;
}
- file_regfree(&rx);
if (v == CAST(uint64_t, -1))
return -1;
break;

@ -0,0 +1,226 @@
diff --git a/src/apprentice.c b/src/apprentice.c
index 21eac1e..781c5e1 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -513,6 +513,9 @@ file_ms_free(struct magic_set *ms)
free(ms->o.pbuf);
free(ms->o.buf);
free(ms->c.li);
+#ifdef USE_C_LOCALE
+ freelocale(ms->c_lc_ctype);
+#endif
free(ms);
}
@@ -551,6 +554,10 @@ file_ms_alloc(int flags)
ms->elf_notes_max = FILE_ELF_NOTES_MAX;
ms->regex_max = FILE_REGEX_MAX;
ms->bytes_max = FILE_BYTES_MAX;
+#ifdef USE_C_LOCALE
+ ms->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
+ assert(ms->c_lc_ctype != NULL);
+#endif
return ms;
free:
free(ms);
@@ -624,6 +631,7 @@ mlist_free_one(struct mlist *ml)
if (ml->magic_rxcomp[i]) {
file_regfree(ml->magic_rxcomp[i]);
free(ml->magic_rxcomp[i]);
+ ml->magic_rxcomp[i] = NULL;
}
}
free(ml->magic_rxcomp);
@@ -2714,7 +2722,8 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
}
if (m->type == FILE_REGEX) {
file_regex_t rx;
- int rc = file_regcomp(&rx, m->value.s, REG_EXTENDED);
+ int rc = file_regcomp(ms, &rx, m->value.s,
+ REG_EXTENDED);
if (rc) {
if (ms->flags & MAGIC_CHECK)
file_regerror(&rx, rc, ms);
diff --git a/src/file.h b/src/file.h
index c0b5a7c..f049446 100644
--- a/src/file.h
+++ b/src/file.h
@@ -173,13 +173,6 @@
typedef struct {
const char *pat;
-#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
-#define USE_C_LOCALE
- locale_t old_lc_ctype;
- locale_t c_lc_ctype;
-#else
- char *old_lc_ctype;
-#endif
int rc;
regex_t rx;
} file_regex_t;
@@ -487,6 +480,10 @@ struct magic_set {
#define FILE_INDIR_MAX 50
#define FILE_NAME_MAX 50
#define FILE_REGEX_MAX 8192
+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
+#define USE_C_LOCALE
+ locale_t c_lc_ctype;
+#endif
};
/* Type for Unicode characters */
@@ -574,9 +571,10 @@ protected int buffer_fill(const struct buffer *);
-protected int file_regcomp(file_regex_t *, const char *, int);
-protected int file_regexec(file_regex_t *, const char *, size_t, regmatch_t *,
+protected int file_regcomp(struct magic_set *, file_regex_t *, const char *,
int);
+protected int file_regexec(struct magic_set *, file_regex_t *, const char *,
+ size_t, regmatch_t *, int);
protected void file_regfree(file_regex_t *);
protected void file_regerror(file_regex_t *, int, struct magic_set *);
diff --git a/src/funcs.c b/src/funcs.c
index 6320cf2..1391a44 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -613,13 +613,13 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
file_regex_t rx;
int rc, rv = -1;
- rc = file_regcomp(&rx, pat, REG_EXTENDED);
+ rc = file_regcomp(ms, &rx, pat, REG_EXTENDED);
if (rc) {
file_regerror(&rx, rc, ms);
} else {
regmatch_t rm;
int nm = 0;
- while (file_regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) {
+ while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) {
ms->o.buf[rm.rm_so] = '\0';
if (file_printf(ms, "%s%s", rep,
rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1)
@@ -634,34 +634,52 @@ out:
}
protected int
-file_regcomp(file_regex_t *rx, const char *pat, int flags)
+file_regcomp(struct magic_set *ms, file_regex_t *rx, const char *pat, int flags)
{
#ifdef USE_C_LOCALE
- rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
- assert(rx->c_lc_ctype != NULL);
- rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
- assert(rx->old_lc_ctype != NULL);
+ locale_t old = uselocale(ms->c_lc_ctype);
+ assert(old != NULL);
#else
- rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
- assert(rx->old_lc_ctype != NULL);
- rx->old_lc_ctype = strdup(rx->old_lc_ctype);
- assert(rx->old_lc_ctype != NULL);
+ char old[1024];
+ strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old));
(void)setlocale(LC_CTYPE, "C");
#endif
rx->pat = pat;
- return rx->rc = regcomp(&rx->rx, pat, flags);
+ rx->rc = regcomp(&rx->rx, pat, flags);
+
+#ifdef USE_C_LOCALE
+ uselocale(old);
+#else
+ (void)setlocale(LC_CTYPE, old);
+#endif
+ return rx->rc;
}
protected int
-file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
- regmatch_t* pmatch, int eflags)
+file_regexec(struct magic_set *ms, file_regex_t *rx, const char *str,
+ size_t nmatch, regmatch_t* pmatch, int eflags)
{
+#ifdef USE_C_LOCALE
+ locale_t old = uselocale(ms->c_lc_ctype);
+ assert(old != NULL);
+#else
+ char old[1024];
+ strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old));
+ (void)setlocale(LC_CTYPE, "C");
+#endif
+ int rc;
assert(rx->rc == 0);
/* XXX: force initialization because glibc does not always do this */
if (nmatch != 0)
memset(pmatch, 0, nmatch * sizeof(*pmatch));
- return regexec(&rx->rx, str, nmatch, pmatch, eflags);
+ rc = regexec(&rx->rx, str, nmatch, pmatch, eflags);
+#ifdef USE_C_LOCALE
+ uselocale(old);
+#else
+ (void)setlocale(LC_CTYPE, old);
+#endif
+ return rc;
}
protected void
@@ -669,13 +687,6 @@ file_regfree(file_regex_t *rx)
{
if (rx->rc == 0)
regfree(&rx->rx);
-#ifdef USE_C_LOCALE
- (void)uselocale(rx->old_lc_ctype);
- freelocale(rx->c_lc_ctype);
-#else
- (void)setlocale(LC_CTYPE, rx->old_lc_ctype);
- free(rx->old_lc_ctype);
-#endif
}
protected void
diff --git a/src/softmagic.c b/src/softmagic.c
index 43338fc..b4052a6 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -478,11 +478,11 @@ check_fmt(struct magic_set *ms, const char *fmt)
if (strchr(fmt, '%') == NULL)
return 0;
- rc = file_regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
+ rc = file_regcomp(ms, &rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
if (rc) {
file_regerror(&rx, rc, ms);
} else {
- rc = file_regexec(&rx, fmt, 0, 0, 0);
+ rc = file_regexec(ms, &rx, fmt, 0, 0, 0);
rv = !rc;
}
file_regfree(&rx);
@@ -2003,11 +2003,12 @@ alloc_regex(struct magic_set *ms, struct magic *m)
return NULL;
}
- rc = file_regcomp(rx, m->value.s, REG_EXTENDED | REG_NEWLINE |
+ rc = file_regcomp(ms, rx, m->value.s, REG_EXTENDED | REG_NEWLINE |
((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0));
if (rc == 0)
return rx;
+fprintf(stderr, "regcomp %s %d\n", m->value.s, rc);
file_regerror(rx, rc, ms);
file_regfree(rx);
free(rx);
@@ -2225,7 +2226,7 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
search = CCAST(char *, "");
copy = NULL;
}
- rc = file_regexec(rx, RCAST(const char *, search),
+ rc = file_regexec(ms, rx, RCAST(const char *, search),
1, &pmatch, 0);
free(copy);
switch (rc) {

@ -0,0 +1,28 @@
From d1a00ae92b2cf09298615cf3aba474d8fec7380f Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 18 Apr 2022 21:46:43 +0000
Subject: [PATCH] From Dirk Mueller:
when name/use was used, the regex caching table was incorrectly
initialized, which led to false or missing matches.
---
src/apprentice.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/apprentice.c b/src/apprentice.c
index 804c0e33e..992102b4e 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -3678,11 +3678,11 @@ file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
continue;
if (strcmp(ma[i].value.s, name) == 0) {
v->magic = &ma[i];
+ v->magic_rxcomp = &(ml->magic_rxcomp[i]);
for (j = i + 1; j < ml->nmagic; j++)
if (ma[j].cont_level == 0)
break;
v->nmagic = j - i;
- v->magic_rxcomp = ml->magic_rxcomp;
return 0;
}
}

@ -0,0 +1,164 @@
diff --git a/src/apprentice.c b/src/apprentice.c
index 781c5e1..50a91cf 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -2724,11 +2724,9 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
file_regex_t rx;
int rc = file_regcomp(ms, &rx, m->value.s,
REG_EXTENDED);
- if (rc) {
- if (ms->flags & MAGIC_CHECK)
- file_regerror(&rx, rc, ms);
+ if (rc == 0) {
+ file_regfree(&rx);
}
- file_regfree(&rx);
return rc ? -1 : 0;
}
return 0;
diff --git a/src/file.h b/src/file.h
index f049446..ee15855 100644
--- a/src/file.h
+++ b/src/file.h
@@ -171,11 +171,7 @@
#define FILE_COMPILE 2
#define FILE_LIST 3
-typedef struct {
- const char *pat;
- int rc;
- regex_t rx;
-} file_regex_t;
+typedef regex_t file_regex_t;
struct buffer {
int fd;
@@ -576,7 +572,6 @@ protected int file_regcomp(struct magic_set *, file_regex_t *, const char *,
protected int file_regexec(struct magic_set *, file_regex_t *, const char *,
size_t, regmatch_t *, int);
protected void file_regfree(file_regex_t *);
-protected void file_regerror(file_regex_t *, int, struct magic_set *);
typedef struct {
char *buf;
diff --git a/src/funcs.c b/src/funcs.c
index 1391a44..df436eb 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -614,9 +614,7 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
int rc, rv = -1;
rc = file_regcomp(ms, &rx, pat, REG_EXTENDED);
- if (rc) {
- file_regerror(&rx, rc, ms);
- } else {
+ if (rc == 0) {
regmatch_t rm;
int nm = 0;
while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) {
@@ -644,16 +642,22 @@ file_regcomp(struct magic_set *ms, file_regex_t *rx, const char *pat, int flags)
strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old));
(void)setlocale(LC_CTYPE, "C");
#endif
- rx->pat = pat;
-
- rx->rc = regcomp(&rx->rx, pat, flags);
+ int rc;
+ rc = regcomp(rx, pat, flags);
#ifdef USE_C_LOCALE
uselocale(old);
#else
(void)setlocale(LC_CTYPE, old);
#endif
- return rx->rc;
+ if (rc > 0 && (ms->flags & MAGIC_CHECK)) {
+ char errmsg[512];
+
+ (void)regerror(rc, rx, errmsg, sizeof(errmsg));
+ file_magerror(ms, "regex error %d for `%s', (%s)", rc, pat,
+ errmsg);
+ }
+ return rc;
}
protected int
@@ -669,11 +673,10 @@ file_regexec(struct magic_set *ms, file_regex_t *rx, const char *str,
(void)setlocale(LC_CTYPE, "C");
#endif
int rc;
- assert(rx->rc == 0);
/* XXX: force initialization because glibc does not always do this */
if (nmatch != 0)
memset(pmatch, 0, nmatch * sizeof(*pmatch));
- rc = regexec(&rx->rx, str, nmatch, pmatch, eflags);
+ rc = regexec(rx, str, nmatch, pmatch, eflags);
#ifdef USE_C_LOCALE
uselocale(old);
#else
@@ -685,18 +688,7 @@ file_regexec(struct magic_set *ms, file_regex_t *rx, const char *str,
protected void
file_regfree(file_regex_t *rx)
{
- if (rx->rc == 0)
- regfree(&rx->rx);
-}
-
-protected void
-file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
-{
- char errmsg[512];
-
- (void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg));
- file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat,
- errmsg);
+ regfree(rx);
}
protected file_pushbuf_t *
diff --git a/src/softmagic.c b/src/softmagic.c
index b4052a6..f469a12 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -474,14 +474,13 @@ check_fmt(struct magic_set *ms, const char *fmt)
{
file_regex_t rx;
int rc, rv = -1;
+ const char* pat = "%[-0-9\\.]*s";
if (strchr(fmt, '%') == NULL)
return 0;
- rc = file_regcomp(ms, &rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
- if (rc) {
- file_regerror(&rx, rc, ms);
- } else {
+ rc = file_regcomp(ms, &rx, pat, REG_EXTENDED|REG_NOSUB);
+ if (rc == 0) {
rc = file_regexec(ms, &rx, fmt, 0, 0, 0);
rv = !rc;
}
@@ -2008,9 +2007,6 @@ alloc_regex(struct magic_set *ms, struct magic *m)
if (rc == 0)
return rx;
-fprintf(stderr, "regcomp %s %d\n", m->value.s, rc);
- file_regerror(rx, rc, ms);
- file_regfree(rx);
free(rx);
return NULL;
}
@@ -2243,12 +2239,9 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
break;
default:
- file_regerror(rx, rc, ms);
- v = CAST(uint64_t, -1);
+ return -1;
break;
}
- if (v == CAST(uint64_t, -1))
- return -1;
break;
}
case FILE_INDIRECT:

@ -0,0 +1,58 @@
From a4b3abc4104d8a4eeb84a6242f2f1a830204a539 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sat, 12 Mar 2022 15:09:47 +0000
Subject: [PATCH] Combine regex's to improve performance adjusting strength to
preserve ranking (Dirk Mueller)
---
magic/Magdir/make | 29 +++++++----------------------
1 file changed, 7 insertions(+), 22 deletions(-)
diff --git a/magic/Magdir/make b/magic/Magdir/make
index f522b4f18..1abdf7a3e 100644
--- a/magic/Magdir/make
+++ b/magic/Magdir/make
@@ -1,36 +1,21 @@
#------------------------------------------------------------------------------
-# $File: make,v 1.4 2018/05/29 17:26:02 christos Exp $
+# $File: make,v 1.5 2022/03/12 15:09:47 christos Exp $
# make: file(1) magic for makefiles
#
# URL: https://en.wikipedia.org/wiki/Make_(software)
-0 regex/100l \^CFLAGS makefile script text
-!:mime text/x-makefile
-0 regex/100l \^VPATH makefile script text
-!:mime text/x-makefile
-0 regex/100l \^LDFLAGS makefile script text
-!:mime text/x-makefile
-0 regex/100l \^all: makefile script text
-!:mime text/x-makefile
-0 regex/100l \^\\.PRECIOUS makefile script text
+0 regex/100l \^(CFLAGS|VPATH|LDFLAGS|all:|\\.PRECIOUS) makefile script text
!:mime text/x-makefile
+!:strength -15
# Update: Joerg Jenderek
# Reference: https://www.freebsd.org/cgi/man.cgi?make(1)
# exclude grub-core\lib\libgcrypt\mpi\Makefile.am with "#BEGIN_ASM_LIST"
# by additional escaping point character
-0 regex/100l \^\\.BEGIN BSD makefile script text
-!:mime text/x-makefile
-!:ext /mk
-!:strength +10
# exclude MS Windows help file CoNtenT with ":include FOOBAR.CNT"
# and NSIS script with "!include" by additional escaping point character
-0 regex/100l \^\\.include BSD makefile script text
-!:mime text/x-makefile
-!:ext /mk
-!:strength +10
-0 regex/100l \^\\.endif BSD makefile script text
+0 regex/100l \^\\.(BEGIN|endif|include) BSD makefile script text
!:mime text/x-makefile
!:ext /mk
-!:strength +10
-0 regex/100l \^SUBDIRS automake makefile script text
+!:strength -10
+0 regex/100l \^SUBDIRS[[:space:]]+= automake makefile script text
!:mime text/x-makefile
-!:strength +10
+!:strength -15

@ -0,0 +1,86 @@
diff --git a/magic/Magdir/archive b/magic/Magdir/archive
index 99798b0..945f536 100644
--- a/magic/Magdir/archive
+++ b/magic/Magdir/archive
@@ -150,7 +150,7 @@
# Incremental snapshot gnu-tar format from:
# https://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html
0 string GNU\ tar- GNU tar incremental snapshot data
->&0 regex [0-9]\.[0-9]+-[0-9]+ version %s
+>&0 regex [0-9]\\.[0-9]+-[0-9]+ version %s
# cpio archives
#
diff --git a/magic/Magdir/ctf b/magic/Magdir/ctf
index ebea8f3..d91684d 100644
--- a/magic/Magdir/ctf
+++ b/magic/Magdir/ctf
@@ -20,4 +20,4 @@
# CTF metadata (plain text)
0 string /*\x20CTF\x20 Common Trace Format (CTF) plain text metadata
!:strength + 5 # this is to make sure we beat C
->&0 regex [0-9]+\.[0-9]+ \b, v%s
+>&0 regex [0-9]+\\.[0-9]+ \b, v%s
diff --git a/magic/Magdir/geo b/magic/Magdir/geo
index d72e514..dda5f73 100644
--- a/magic/Magdir/geo
+++ b/magic/Magdir/geo
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
-# $File: geo,v 1.7 2019/04/19 00:42:27 christos Exp $
+# $File: geo,v 1.8 2022/03/24 15:48:58 christos Exp $
# Geo- files from Kurt Schwehr <schwehr@ccom.unh.edu>
######################################################################
@@ -28,8 +28,8 @@
# Knudsen subbottom chirp profiler - Binary File Format: B9
# KEB D409-03167 V1.75 Huffman
0 string KEB\ Knudsen seismic KEL binary (KEB) -
->4 regex [-A-Z0-9]* Software: %s
->>&1 regex V[0-9]*\.[0-9]* version %s
+>4 regex [-A-Z0-9]+ Software: %s
+>>&1 regex V[0-9]+\\.[0-9]+ version %s
######################################################################
#
@@ -40,7 +40,7 @@
# Caris LIDAR format for LADS comes as two parts... ascii location file and binary waveform data
0 string HCA LADS Caris Ascii Format (CAF) bathymetric lidar
->4 regex [0-9]*\.[0-9]* version %s
+>4 regex [0-9]+\\.[0-9]+ version %s
0 string HCB LADS Caris Binary Format (CBF) bathymetric lidar waveform data
>3 byte x version %d .
@@ -69,7 +69,7 @@
# mb121 https://www.saic.com/maritime/gsf/
8 string GSF-v SAIC generic sensor format (GSF) sonar data,
->&0 regex [0-9]*\.[0-9]* version %s
+>&0 regex [0-9]+\\.[0-9]+ version %s
# MGD77 - https://www.ngdc.noaa.gov/mgg/dat/geodas/docs/mgd77.htm
# mb161
diff --git a/magic/Magdir/windows b/magic/Magdir/windows
index 8a7923f..1247e03 100644
--- a/magic/Magdir/windows
+++ b/magic/Magdir/windows
@@ -358,7 +358,7 @@
# skip space at beginning
>0 string \040
# name without extension and greater character or name with hlp extension
->>1 regex/c \^([^\xd>]*|.*\.hlp) MS Windows help file Content, based "%s"
+>>1 regex/c \^([^\xd>]*|.*\\.hlp) MS Windows help file Content, based "%s"
!:mime text/plain
!:apple ????TEXT
!:ext cnt
@@ -535,7 +535,7 @@
# http://www.winfaq.de/faq_html/Content/tip2500/onlinefaq.php?h=tip2653.htm
# https://msdn.microsoft.com/en-us/library/windows/desktop/cc144102.aspx
# .ShellClassInfo DeleteOnCopy LocalizedFileNames ASCII coded case-independent
->>&0 regex/c \^(\.ShellClassInfo|DeleteOnCopy|LocalizedFileNames)] Windows desktop.ini
+>>&0 regex/1024c \^(\\.ShellClassInfo|DeleteOnCopy|LocalizedFileNames)] Windows desktop.ini
!:mime application/x-wine-extension-ini
#!:mime text/plain
# https://support.microsoft.com/kb/84709/

@ -0,0 +1,79 @@
From 14b5d7aa0b55275969809fdf84e8a8caee857c0f Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 18 Apr 2022 21:38:10 +0000
Subject: [PATCH] From Dirk Mueller: * regex rules need literal dots escaped,
otherwise they are considered any character * literal search strings can be
searched using search rather than the much more expensive regex * use
standard xml declaration search as used in other format matchers * only match
the first 1024 bytes, the information we look for should be in the very
first tag * remove unnecessary parentheses
---
magic/Magdir/dataone | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/magic/Magdir/dataone b/magic/Magdir/dataone
index 8ef3f7981..566633eff 100644
--- a/magic/Magdir/dataone
+++ b/magic/Magdir/dataone
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
-# $File: dataone,v 1.2 2019/04/19 00:42:27 christos Exp $
+# $File: dataone,v 1.3 2022/04/18 21:38:10 christos Exp $
#
# DataONE- files from Dave Vieglais <dave.vieglais@gmail.com> &
# Pratik Shrivastava <pratikshrivastava23@gmail.com>
@@ -9,39 +9,39 @@
#------------------------------------------------------------------------------
# EML (Ecological Metadata Language Format)
-0 string <?xml
->&0 regex (eml)-[0-9].[0-9].[0-9]+ eml://ecoinformatics.org/%s
+0 string \<?xml\ version=
+>&0 regex/1024 eml-[0-9]\\.[0-9]\\.[0-9]+ eml://ecoinformatics.org/%s
# onedcx (DataONE Dublin Core Extended v1.0)
->&0 regex (onedcx/v)[0-9].[0-9]+ https://ns.dataone.org/metadata/schema/onedcx/v1.0
+>&0 regex/1024 onedcx/v[0-9]\\.[0-9]+ https://ns.dataone.org/metadata/schema/onedcx/v1.0
# FGDC-STD-001-1998 (Content Standard for Digital Geospatial Metadata,
# version 001-1998)
->&0 regex fgdc FGDC-STD-001-1998
+>&0 search/1024 fgdc FGDC-STD-001-1998
# Mercury (Oak Ridge National Lab Mercury Metadata version 1.0)
->&0 regex (mercury/terms/v)[0-9].[0-9] https://purl.org/ornl/schema/mercury/terms/v1.0
+>&0 regex/1024 mercury/terms/v[0-9]\\.[0-9] https://purl.org/ornl/schema/mercury/terms/v1.0
# ISOTC211 (Geographic MetaData (GMD) Extensible Markup Language)
->&0 regex isotc211
->>&0 regex eng;USA https://www.isotc211.org/2005/gmd
+>&0 search/1024 isotc211
+>>&0 search/1024 eng;USA https://www.isotc211.org/2005/gmd
# ISOTC211 (NOAA Variant Geographic MetaData (GMD) Extensible Markup Language)
->>&0 regex gov.noaa.nodc:[0-9]+ https://www.isotc211.org/2005/gmd-noaa
+>>&0 regex/1024 gov\\.noaa\\.nodc:[0-9]+ https://www.isotc211.org/2005/gmd-noaa
# ISOTC211 PANGAEA Variant Geographic MetaData (GMD) Extensible Markup Language
->>&0 regex pangaea.dataset[0-9][0-9][0-9][0-9][0-9][0-9]+ https://www.isotc211.org/2005/gmd-pangaea
+>>&0 regex/1024 pangaea\\.dataset[0-9][0-9][0-9][0-9][0-9][0-9]+ https://www.isotc211.org/2005/gmd-pangaea
!:mime text/xml
# Object Reuse and Exchange Vocabulary
-0 string <?xml
->&0 regex rdf
->>&0 regex openarchives https://www.openarchives.org/ore/terms
+0 string \<?xml\ version=
+>&0 search/1024 rdf
+>>&0 search/1024 openarchives https://www.openarchives.org/ore/terms
!:mime application/rdf+xml
# Dryad Metadata Application Profile Version 3.1
0 string <DryadData
->&0 regex (dryad-bibo/v)[0-9].[0-9] https://datadryad.org/profile/v3.1
+>&0 regex/1024 dryad-bibo/v[0-9]\\.[0-9] https://datadryad.org/profile/v3.1
!:mime text/xml

@ -1,19 +1,27 @@
From 948d0e24f33c3b411b5ec1e320acec889e6781b8 Mon Sep 17 00:00:00 2001
From: Vincent Mihalkovic <vmihalko@redhat.com>
Date: Mon, 6 Feb 2023 15:04:33 +0100
From 363d7fcf703ad3ebf37b45693b2c9e43eb8b4176 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Sat, 22 Aug 2020 18:04:18 +0000
Subject: [PATCH] Improve detection of static-pie binaries, and don't call them
"dynamically linked", but call them "static-pie" linked.
363d7fcf703ad3ebf37b45693b2c9e43eb8b4176
---
src/readelf.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
src/readelf.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index 9c75c0a..0011659 100644
index cf1dc91b7..d390d5f6a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1040,7 +1040,7 @@ do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
@@ -27,7 +27,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.173 2020/06/07 22:12:54 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.174 2020/08/22 18:04:18 christos Exp $")
#endif
#ifdef BUILTIN_ELF
@@ -1099,7 +1099,7 @@ do_auxv_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
private size_t
dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
@ -22,7 +30,7 @@ index 9c75c0a..0011659 100644
{
Elf32_Dyn dh32;
Elf64_Dyn dh64;
@@ -1058,11 +1058,15 @@ dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
@@ -1117,11 +1117,15 @@ dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
switch (xdh_tag) {
case DT_FLAGS_1:
@ -38,7 +46,7 @@ index 9c75c0a..0011659 100644
default:
break;
}
@@ -1529,9 +1533,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
@@ -1608,9 +1612,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
/*
@ -52,7 +60,7 @@ index 9c75c0a..0011659 100644
*/
private int
dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
@@ -1540,12 +1545,13 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
@@ -1619,12 +1624,13 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
@ -66,17 +74,17 @@ index 9c75c0a..0011659 100644
+ size_t offset, align, len, need = 0;
+ int pie = 0, dynamic = 0;
if (size != xph_sizeof) {
if (file_printf(ms, ", corrupted program header size") == -1)
@@ -1569,7 +1575,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
/* Things we can determine before we seek */
if (num == 0) {
if (file_printf(ms, ", no program header") == -1)
@@ -1654,7 +1660,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
switch (xph_type) {
case PT_DYNAMIC:
- linking_style = "dynamically";
doread = 1;
- linking_style = "dynamically";
break;
case PT_NOTE:
@@ -1610,6 +1615,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
if (sh_num) /* Did this through section headers */
@@ -1694,6 +1699,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
/* Things we can determine when we seek */
switch (xph_type) {
case PT_DYNAMIC:
@ -84,8 +92,8 @@ index 9c75c0a..0011659 100644
offset = 0;
// Let DF_1 determine if we are PIE or not.
ms->mode &= ~0111;
@@ -1617,7 +1623,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
if (offset >= (size_t)bufsize)
@@ -1701,7 +1707,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
if (offset >= CAST(size_t, bufsize))
break;
offset = dodynamic(ms, nbuf, offset,
- CAST(size_t, bufsize), clazz, swap);
@ -94,7 +102,7 @@ index 9c75c0a..0011659 100644
if (offset == 0)
break;
}
@@ -1626,6 +1633,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
@@ -1710,6 +1717,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
break;
case PT_INTERP:
@ -102,7 +110,7 @@ index 9c75c0a..0011659 100644
if (ms->flags & MAGIC_MIME)
continue;
if (bufsize && nbuf[0]) {
@@ -1660,8 +1668,15 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
@@ -1744,8 +1752,15 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
if (ms->flags & MAGIC_MIME)
return 0;
@ -120,6 +128,3 @@ index 9c75c0a..0011659 100644
return -1;
if (interp[0])
if (file_printf(ms, ", interpreter %s",
--
2.39.1

@ -0,0 +1,23 @@
From 85b7ab83257b3191a1a7ca044589a092bcef2bb3 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Thu, 25 Jun 2020 16:52:48 +0000
Subject: [PATCH] Include # (alternate format) to the list of uninteresting
formats Reported by Werner Fink
---
src/funcs.c | 2 ++--
1 file changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/funcs.c b/src/funcs.c
index 299b8f022..ecbfa28c5 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -93,7 +93,7 @@ file_checkfmt(char *msg, size_t mlen, const char *fmt)
if (*++p == '%')
continue;
// Skip uninteresting.
- while (strchr("0.'+- ", *p) != NULL)
+ while (strchr("#0.'+- ", *p) != NULL)
p++;
if (*p == '*') {
if (msg)

@ -0,0 +1,319 @@
diff --git a/magic/Magdir/python b/magic/Magdir/python
index 9d306c0..bc5163e 100644
--- a/magic/Magdir/python
+++ b/magic/Magdir/python
@@ -10,211 +10,211 @@
# MAGIC as specified in Python/import.c (1.0 to 3.7)
# two bytes of magic followed by "\r\n" in little endian order
0 belong 0x02099900 python 1.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x03099900 python 1.1/1.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x892e0d0a python 1.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x04170d0a python 1.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x994e0d0a python 1.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xfcc40d0a python 1.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xfdc40d0a python 1.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x87c60d0a python 2.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x88c60d0a python 2.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2aeb0d0a python 2.1 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2beb0d0a python 2.1 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2ded0d0a python 2.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2eed0d0a python 2.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x3bf20d0a python 2.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x3cf20d0a python 2.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x45f20d0a python 2.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x59f20d0a python 2.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x63f20d0a python 2.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x6df20d0a python 2.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x6ef20d0a python 2.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x77f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x81f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x8bf20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x8cf20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x95f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x9ff20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xa9f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xb3f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xb4f20d0a python 2.5 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xc7f20d0a python 2.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xd1f20d0a python 2.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xd2f20d0a python 2.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xdbf20d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xe5f20d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xeff20d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xf9f20d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x03f30d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x04f30d0a python 2.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xb80b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xc20b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xcc0b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xd60b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xe00b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xea0b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xf40b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xf50b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xff0b0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x090c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x130c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x1d0c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x1f0c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x270c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x3b0c0d0a python 3.0 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x450c0d0a python 3.1 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x4f0c0d0a python 3.1 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x580c0d0a python 3.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x620c0d0a python 3.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x6c0c0d0a python 3.2 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x760c0d0a python 3.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x800c0d0a python 3.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x8a0c0d0a python 3.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x940c0d0a python 3.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x9e0c0d0a python 3.3 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xb20c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xbc0c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xc60c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xd00c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xda0c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xe40c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xee0c0d0a python 3.4 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0xf80c0d0a python 3.5.1- byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x020d0d0a python 3.5.1- byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x0c0d0d0a python 3.5.1- byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x160d0d0a python 3.5.1- byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x170d0d0a python 3.5.2+ byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x200d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x210d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2a0d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2b0d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2c0d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2d0d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x2f0d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x300d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x310d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x320d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x330d0d0a python 3.6 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x3e0d0d0a python 3.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x3f0d0d0a python 3.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x400d0d0a python 3.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x410d0d0a python 3.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x420d0d0a python 3.7 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x480d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x490d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x520d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x530d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x540d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x550d0d0a python 3.8 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x5c0d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x5d0d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x5e0d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x5f0d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x600d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 belong 0x610d0d0a python 3.9 byte-compiled
-!:mime text/x-bytecode.python
+!:mime application/x-bytecode.python
0 search/1/w #!\040/usr/bin/python Python script text executable
!:strength + 15

@ -0,0 +1,31 @@
From ea6256a346adbd65ac1d646d716e7b51ea0b9232 Mon Sep 17 00:00:00 2001
From: Ville-Pekka Vainio <vpvainio@iki.fi>
Date: Fri, 9 Jun 2023 12:00:27 +0300
Subject: [PATCH] FlateDecode does not mean password protected
Have the patch apply against file-5.39 in EL9
Upstream bug: https://bugs.astron.com/view.php?id=275
Upstream commit: https://github.com/file/file/commit/239852073ad3a5ba5cf62b21e95565f122869f6a
Original author: pwinckles
Signed-off-by: Ville-Pekka Vainio <vpvainio@iki.fi>
---
magic/Magdir/pdf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/magic/Magdir/pdf b/magic/Magdir/pdf
index e386f454..7aa7a24d 100644
--- a/magic/Magdir/pdf
+++ b/magic/Magdir/pdf
@@ -5,7 +5,7 @@
#
0 name pdf
->8 search/512 /Filter/FlateDecode/ (password protected)
+>8 search/512 /Filter/FlateDecode/ (zip deflate encoded)
0 string %PDF- PDF document
!:mime application/pdf
--
2.40.1

@ -1,77 +0,0 @@
diff --git a/python/magic.py b/python/magic.py
index 662569e..2be58cd 100644
--- a/python/magic.py
+++ b/python/magic.py
@@ -5,6 +5,7 @@ Python bindings for libmagic
'''
import ctypes
+import threading
from collections import namedtuple
@@ -241,11 +242,25 @@ def open(flags):
# Objects used by `detect_from_` functions
-mime_magic = Magic(_open(MAGIC_MIME))
-mime_magic.load()
-none_magic = Magic(_open(MAGIC_NONE))
-none_magic.load()
-
+class MagicDetect(object):
+ def __init__(self):
+ self.mime_magic = Magic(_open(MAGIC_MIME))
+ self.mime_magic.load()
+ self.none_magic = Magic(_open(MAGIC_NONE))
+ self.none_magic.load()
+
+ def __del__(self):
+ self.mime_magic.close()
+ self.none_magic.close()
+
+threadlocal = threading.local()
+
+def _detect_make():
+ v = getattr(threadlocal, "magic_instance", None)
+ if v is None:
+ v = MagicDetect()
+ setattr(threadlocal, "magic_instance", v)
+ return v
def _create_filemagic(mime_detected, type_detected):
mime_type, mime_encoding = mime_detected.split('; ')
@@ -259,9 +274,9 @@ def detect_from_filename(filename):
Returns a `FileMagic` namedtuple.
'''
-
- return _create_filemagic(mime_magic.file(filename),
- none_magic.file(filename))
+ x = _detect_make()
+ return _create_filemagic(x.mime_magic.file(filename),
+ x.none_magic.file(filename))
def detect_from_fobj(fobj):
@@ -271,8 +286,9 @@ def detect_from_fobj(fobj):
'''
file_descriptor = fobj.fileno()
- return _create_filemagic(mime_magic.descriptor(file_descriptor),
- none_magic.descriptor(file_descriptor))
+ x = _detect_make()
+ return _create_filemagic(x.mime_magic.descriptor(file_descriptor),
+ x.none_magic.descriptor(file_descriptor))
def detect_from_content(byte_content):
@@ -281,5 +297,6 @@ def detect_from_content(byte_content):
Returns a `FileMagic` namedtuple.
'''
- return _create_filemagic(mime_magic.buffer(byte_content),
- none_magic.buffer(byte_content))
+ x = _detect_make()
+ return _create_filemagic(x.mime_magic.buffer(byte_content),
+ x.none_magic.buffer(byte_content))

@ -1,11 +1,9 @@
From f25107f625e88726e8ae9d4963573b5a0dda8f4c Mon Sep 17 00:00:00 2001
From: Jan Kaluza <hanzz.k@gmail.com>
Date: Thu, 15 Dec 2011 16:15:41 +0100
Subject: [PATCH] file-localmagic.patch
From 95c993ff6bdfe92a7f519c4db60157a421e65b38 Mon Sep 17 00:00:00 2001
From: Siteshwar Vashisht <svashisht@redhat.com>
Date: Thu, 21 Feb 2019 15:26:38 +0100
Subject: [PATCH] Upstream says it's up to distributions to add a way to
support local-magic.
Upstream says it's up to distributions to add a way to support local-magic.
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
magic/magic.local | 3 +++
src/Makefile.am | 2 +-
@ -24,7 +22,7 @@ index 0000000..283a863
+# Insert here your local magic data. Format is described in magic(5).
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 155aec4..0f22539 100644
index 3f67f2c..b43cb8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
@ -34,10 +32,10 @@ index 155aec4..0f22539 100644
nodist_include_HEADERS = magic.h
diff --git a/src/Makefile.in b/src/Makefile.in
index b6eeb20..78dce55 100644
index 59f3b5e..a8f56cf 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -337,7 +337,7 @@ target_alias = @target_alias@
@@ -356,7 +356,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
@ -47,12 +45,12 @@ index b6eeb20..78dce55 100644
nodist_include_HEADERS = magic.h
AM_CPPFLAGS = -DMAGIC='"$(MAGIC)"'
diff --git a/src/apprentice.c b/src/apprentice.c
index e395854..ecc1214 100644
index 1437bcc..b609dd1 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -454,7 +454,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
if (map == (struct magic_map *)-1)
return -1;
@@ -460,7 +460,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
#ifndef COMPILE_ONLY
map = apprentice_map(ms, fn);
if (map == NULL) {
- if (ms->flags & MAGIC_CHECK)
+ if (ms->flags & MAGIC_CHECK && strcmp("/etc/magic", fn) != 0)
@ -60,5 +58,5 @@ index e395854..ecc1214 100644
map = apprentice_load(ms, fn, action);
if (map == NULL)
--
2.5.5
2.25.4

@ -1,13 +0,0 @@
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
index eb41868f..44805a35 100644
--- a/magic/Magdir/filesystems
+++ b/magic/Magdir/filesystems
@@ -1973,7 +1973,7 @@
# to display CD-ROM (70=81-11) after MBR (113=40+72+1), partition-table (71=50+21) and before Apple Driver Map (51)
#!:strength -11
# to display CD-ROM (114=81+33) before MBR (113=40+72+1), partition-table (71=50+21) and Apple Driver Map (51)
-!:strength +34
+!:strength +35
>0 use cdrom
# URL: https://en.wikipedia.org/wiki/NRG_(file_format)

@ -5,20 +5,19 @@
%bcond_with python3
%endif
# python2 is not available on RHEL > 7 and not needed on Fedora > 29
%if 0%{?rhel} > 7 || 0%{?fedora} > 29
# python2 is not available on RHEL > 7
%if 0%{?fedora} > 31 || 0%{?rhel} > 7
%bcond_with python2
%else
%bcond_without python2
%endif
Summary: A utility for determining file types
Summary: Utility for determining file types
Name: file
Version: 5.33
Release: 26%{?dist}
Version: 5.39
Release: 14%{?dist}
License: BSD
Group: Applications/File
Source0: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz
Source0: http://ftp.astron.com/pub/file/file-%{version}.tar.gz
# Upstream says it's up to distributions to add a way to support local-magic.
Patch0: file-localmagic.patch
@ -27,93 +26,46 @@ Patch0: file-localmagic.patch
Patch1: file-4.17-rpm-name.patch
Patch2: file-5.04-volume_key.patch
# picked from upstream
Patch3: file-5.33-gif.patch
Patch4: file-5.33-seccomp.patch
# Fix close_on_exec multithreaded decompression issue (#1906751)
Patch3: file-5.39-CLOEXEC.patch
# do not classify shared libraries as pie executables (#1581343)
Patch5: file-5.33-pie-executable-revert.patch
# Upstream commit 7d9b0f0d853957ad88dae0f440fecd58d2740ca7 (#1963892)
Patch4: file-5.40-magic-python.patch
# fix out-of-bounds read via a crafted ELF file (CVE-2018-10360)
Patch6: file-5.33-CVE-2018-10360.patch
# Upstream commit 239852073ad3a5ba5cf62b21e95565f122869f6a (#2213761)
Patch5: file-5.41-pdf-deflate-not-password-protected.patch
# support longer version strings for clamav database (#1539107)
Patch7: file-5.33-clamav.patch
# show details about ppc swap partition (#1224668)
Patch8: file-5.33-ppc-swap.patch
# fix memory leak on an error path (#1602492)
Patch9: file-5.33-covscan.patch
# add magic for eBPF objects (#1648667)
Patch10: file-5.34-ebpf-magic.patch
# make netpbm beat DOS/MBR magic again (#1658158)
Patch11: file-5.35-netpbm.patch
# improve parsing of ppc core files (#1658171)
Patch12: file-5.35-ppc-core.patch
# improve documentation of --apple in file(1) man page (#1677442)
Patch13: file-5.35-man-apple.patch
# remove wrong magic for JFFS file system (#1773477)
Patch14: file-5.37-jffs-magic.patch
# increase CDROM strength to beat MBR (#1696798)
Patch15: file-magic-filesystems.patch
# search deeper in the zip file (#1845169)
Patch16: file-5.33-msooxml-magic.patch
# when ignoring whitespace compare up to the length of the string
Patch17: file-5.33-whitespace-compare.patch
# Use \040 to make space clearer
Patch18: file-5.33-python-space.patch
# Pass an upper bound to file_strncmp (string is not always NULL)
Patch19: file-5.33-bound-file_strncmp.patch
# improve magic for python scripts
Patch20: file-5.33-more-python.patch
# improve magic for Shell, Gnome Javascript and TCL scripts
Patch21: file-5.33-other-languages.patch
# fix heap-based buffer overflow in cdf_read_property_info() (CVE-2019-18218)
Patch22: file-5.37-CVE-2019-18218.patch
# not yet upstream (#2095828)
Patch23: file-5.33-fix-compression.patch
# upstream commit: 709dfecf25c2eb2822f7e0b8c30d6329cd2d97fb (#2061557)
Patch24: file-5.33-floating-point-exception.patch
# upstream commit: e2adab1456c2bd8b005ddf8ed71540a37d05cb08 (#2071581)
Patch25: file-5.33-static-PIE-binaries-0.patch
# upstream commit: 9109a696f3289ba00eaa222fd432755ec4287e28 (#2071581)
Patch26: file-5.33-static-PIE-binaries-1.patch
# upstream commit: 9ffbd485ba4647827c4bdacf3a2de690f6765b0c (#2071581)
Patch27: file-5.33-static-PIE-binaries-2.patch
# upstream commit: 03084b161cf888b5286dbbcd964c31ccad4f64d9 (#2071581)
Patch28: file-5.33-static-PIE-binaries-3.patch
# upstream commit: 363d7fcf703ad3ebf37b45693b2c9e43eb8b4176 (#2071581)
Patch29: file-5.33-static-PIE-binaries-4.patch
# upstream commit: 9c3137904e59d68debb97fceaced46a691ba241a (#2071581)
Patch30: file-5.33-static-PIE-binaries-5.patch
# https://github.com/file/file/commit/39e43a669d1260f0df36f0b2e78b3012ffd5f086 (#2158115)
Patch31: file-5.33-thermocam-magic.patch
# Upstream commit c8deb32eab1089d1841482fb2e91833f114b6712 (#13737)
Patch32: file-5.41-python-magic-threads.patch
URL: http://www.darwinsys.com/file/
Requires: file-libs = %{version}-%{release}
# not yet upstream
Patch6: file-5.33-fix-compression.patch
# Upstream commit 4c8a4d8dbab1e73bfb30e391dcec49fcf269f84d (#2120692)
Patch7: file-5.39-regex-caching-1.patch
# Upstream commit 7d438e28c16773e28a3707935c8e5d9927a515a7 (#2120692)
Patch8: file-5.39-regex-caching-2.patch
# Upstream commit d1a00ae92b2cf09298615cf3aba474d8fec7380f (#2120692)
Patch9: file-5.39-regex-caching-3.patch
# Upstream commit 4254a0afecfd2ae200c694dfcf93f4b4ac21652e (#2120692)
Patch10: file-5.39-regex-caching-4.patch
# Upstream commit a4b3abc4104d8a4eeb84a6242f2f1a830204a539 (#2120692)
Patch11: file-5.39-regex-combinations.patch
# Upstream commit d17d8e9ff8ad8e95fdf66239ccdcc2133d1ce5ce (#2120692)
Patch12: file-5.39-regex-escape.patch
# Upstream commit 14b5d7aa0b55275969809fdf84e8a8caee857c0f (#2120692)
Patch13: file-5.39-regex-optimalizations.patch
# Upstream commit 709dfecf25c2eb2822f7e0b8c30d6329cd2d97fb (#2164840)
Patch14: file-5.39-floating-point-exception.patch
# Upstream commit 363d7fcf703ad3ebf37b45693b2c9e43eb8b4176 (#2164834)
Patch15: file-5.39-static-PIE-binaries.patch
# Upstream commit 85b7ab83257b3191a1a7ca044589a092bcef2bb3 (#2219392)
Patch16: file-5.39-wasm-magic.patch
URL: https://www.darwinsys.com/file/
Requires: file-libs%{?_isa} = %{version}-%{release}
BuildRequires: zlib-devel
BuildRequires: autoconf automake libtool
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libtool
BuildRequires: make
%description
The file command is used to identify a particular file according to the
@ -123,7 +75,6 @@ different graphics formats.
%package libs
Summary: Libraries for applications using libmagic
Group: Applications/File
License: BSD
%description libs
@ -132,22 +83,24 @@ Libraries for applications using libmagic.
%package devel
Summary: Libraries and header files for file development
Group: Applications/File
Requires: %{name} = %{version}-%{release}
Requires: file-libs%{?_isa} = %{version}-%{release}
%description devel
The file-devel package contains the header files and libmagic library
necessary for developing programs using libmagic.
%package static
Summary: Static library for file development
Requires: file-devel = %{version}-%{release}
%description static
The file-static package contains the static version of the libmagic library.
%if %{with python2}
%package -n python2-magic
Summary: Python 2 bindings for the libmagic API
Group: Development/Libraries
BuildRequires: python2-devel
%if 0%{?rhel} && 0%{?rhel} <= 7
BuildRequires: python-setuptools
%endif
BuildRequires: python2-setuptools
BuildArch: noarch
Requires: %{name} = %{version}-%{release}
%{?python_provide:%python_provide python2-magic}
@ -159,14 +112,17 @@ file(1) command.
%endif
%if %{with python3}
%package -n python3-magic
%package -n python3-file-magic
Summary: Python 3 bindings for the libmagic API
Group: Development/Libraries
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildArch: noarch
Requires: %{name} = %{version}-%{release}
Provides: python3-magic = %{version}-%{release}
Obsoletes: python3-magic < %{version}-%{release}
Conflicts: python3-magic < %{version}-%{release}
%description -n python3-magic
%description -n python3-file-magic
This package contains the Python 3 bindings to allow access to the
libmagic API. The libmagic library is also used by the familiar
file(1) command.
@ -189,12 +145,12 @@ cp -a python %{py3dir}
autoreconf -fi
CFLAGS="%{optflags} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE" \
%configure --enable-fsect-man5 --disable-rpath
%configure --enable-fsect-man5 --disable-rpath --enable-static
# remove hardcoded library paths from local libtool
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
export LD_LIBRARY_PATH=%{_builddir}/%{name}-%{version}/src/.libs
make %{?_smp_mflags} V=1
%make_build
%if %{with python2}
cd python
CFLAGS="%{optflags}" %{__python2} setup.py build
@ -211,7 +167,7 @@ mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man5
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/misc
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/file
make DESTDIR=${RPM_BUILD_ROOT} install
%make_install
rm -f ${RPM_BUILD_ROOT}%{_libdir}/*.la
# local magic in /etc/magic
@ -235,7 +191,6 @@ cd %{py3dir}
%ldconfig_scriptlets libs
%files
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc ChangeLog README
%{_bindir}/*
@ -243,7 +198,6 @@ cd %{py3dir}
%config(noreplace) %{_sysconfdir}/magic
%files libs
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc ChangeLog README
%{_libdir}/*so.*
@ -256,12 +210,15 @@ cd %{py3dir}
%{_libdir}/*.so
%{_includedir}/magic.h
%{_mandir}/man3/*
%{_libdir}/pkgconfig/libmagic.pc
%files static
%{_libdir}/libmagic.a
%if %{with python2}
%files -n python2-magic
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc python/README python/example.py
%doc python/README.md python/example.py
%{python2_sitelib}/magic.py
%{python2_sitelib}/magic.pyc
%{python2_sitelib}/magic.pyo
@ -271,81 +228,171 @@ cd %{py3dir}
%endif
%if %{with python3}
%files -n python3-magic
%{!?_licensedir:%global license %%doc}
%files -n python3-file-magic
%license COPYING
%doc python/README python/example.py
%doc python/README.md python/example.py
%{python3_sitelib}/magic.py
%{python3_sitelib}/*egg-info
%{python3_sitelib}/__pycache__/*
%endif
%changelog
* Fri Mar 29 2024 MSVSphere Packaging Team <packager@msvsphere-os.ru> - 5.33-26
- Rebuilt for MSVSphere 8.10 beta
* Tue Jul 11 2023 Ville-Pekka Vainio <vpvainio@iki.fi> - 5.39-14
- fix detection of deflate encoded PDFs
Resolves: #2213761
* Mon Jul 03 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-13
- fix recognition of wasm files
Resolves: #2219392
* Wed Feb 01 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-12
- fix detection of static-pie binaries
Resolves: #2164834
* Tue Jan 31 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-11
- fix issue with libmagic and floating point exceptions
Resolves: #2061557
* Wed Aug 24 2022 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-10
- speedup magic matching
Resolves: #2120692
* Wed Aug 17 2022 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-9
- fix recognition (src/compress.c) of compressed empty files
Resolves: #2121694
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 5.39-8
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Mon Aug 9 2021 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-7
- do not classify python bytecode files as text.
Resolves: #1963892
* Thu Apr 15 2021 Mohan Boddu <mboddu@redhat.com> - 5.39-6
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 5.39-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Wed Dec 16 2020 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-4
- Fix close_on_exec multithreaded decompression issue (#1906751)
* Mon Jul 27 2020 Fedora Release Engineering <releng@fedoraproject.org> - 5.39-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Wed Jun 24 2020 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-2
- BuildRequires: python3-setuptools
* Tue Jun 16 2020 Vincent Mihalkovic <vmihalko@redhat.com> - 5.39-1
- update to new version 5.39
* Thu Oct 12 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-26
- Fix segfault in python3-file-magic concurrent method calls (#13737)
* Wed May 27 2020 Miro Hrončok <mhroncok@redhat.com> - 5.38-6
- Rebuilt for Python 3.9
* Thu Apr 20 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-25
- Improve thermocam magic (rhbz#2158115)
* Tue May 26 2020 Vincent Mihalkovič <vmihalko@redhat.com> - 5.38-5
- increase CDROM strength to beat MBR (#1696798)
* Wed Feb 22 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-24
- fix detection of static-pie binaries (#2071581)
* Sat May 23 2020 Miro Hrončok <mhroncok@redhat.com> - 5.38-4
- Rebuilt for Python 3.9
* Wed Feb 01 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-23
- fix detection of static-pie binaries (#2071581)
* Wed Mar 11 2020 Vincent Mihalkovič <vmihalko@redhat.com> - 5.38-3
- use python3-file-magic instead of python3-magic (#1793689)
* Tue Jan 31 2023 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-22
- fix issue with libmagic and floating point exceptions (#2061557)
* Tue Jan 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 5.38-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Wed Aug 17 2022 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-21
- fix recognition (src/compress.c) of compressed empty files (#2095828)
* Tue Dec 17 2019 Kamil Dudka <kdudka@redhat.com> - 5.38-1
- update to new version 5.38
* Tue May 04 2021 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-20
- rebuild (#1954434)
* Mon Nov 18 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-9
- remove wrong magic for JFFS file system (#1771242)
* Wed Apr 14 2021 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-18
* Fri Oct 25 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-8
- fix heap-based buffer overflow in cdf_read_property_info() (CVE-2019-18218)
* Thu Jan 21 2021 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-17
- improve magic for script recognition and other changes (#1903531)
* Mon Oct 14 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-7
- remove the python2-magic subpackage on f32+ (#1761223)
* Mon Jun 22 2020 Vincent Mihalkovic <vmihalko@redhat.com> - 5.33-16
- magic/Magdir/msooxml: Search deeper in the zip file (#1845169)
* Fri Oct 04 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-6
- always install python2-setuptools if python2 is enabled
* Fri May 22 2020 Kamil Dudka <kdudka@redhat.com> - 5.33-15
- remove duplicate line in file(1) man page (#1677442)
* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 5.37-5
- Rebuilt for Python 3.8.0rc1 (#1748018)
* Thu May 21 2020 Vincent Mihalkovič <vmihalko@redhat.com> - 5.33-14
- increase magic/Magdir/filesystems CDROM strength to beat MBR (#1696798)
* Fri Aug 16 2019 Miro Hrončok <mhroncok@redhat.com> - 5.37-4
- Rebuilt for Python 3.8
* Mon Nov 18 2019 Kamil Dudka <kdudka@redhat.com> - 5.33-13
- remove wrong magic for JFFS file system (#1773477)
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 5.37-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Tue Oct 15 2019 Kamil Dudka <kdudka@redhat.com> - 5.33-12
- restore missing comma in the output for core files (#1658171)
* Tue Jun 11 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-2
- fix double free on read error (#1685217)
* Tue Oct 15 2019 Kamil Dudka <kdudka@redhat.com> - 5.33-11
- improve documentation of --apple in file(1) man page (#1677442)
- improve parsing of ppc core files (#1658171)
* Fri May 17 2019 Kamil Dudka <kdudka@redhat.com> - 5.37-1
- update to new version 5.37
* Mon Oct 14 2019 Kamil Dudka <kdudka@redhat.com> - 5.33-10
- make netpbm beat DOS/MBR magic again (#1658158)
* Fri Mar 01 2019 Kamil Dudka <kdudka@redhat.com> - 5.36-2
- improve support for Apple formats (#1679455)
* Wed Jul 03 2019 Kamil Dudka <kdudka@redhat.com> - 5.33-9
- add magic for eBPF objects (#1652993)
* Thu Feb 21 2019 Siteshwar Vashisht <svashisht@redhat.com> - 5.36-1
- update to new version 5.36, which fixes the following vulnerabilities:
CVE-2019-8907 - remote denial of service in do_core_note in readelf.c
CVE-2019-8905 - stack-based buffer over-read in do_core_note in readelf.c
CVE-2019-8904 - stack-based buffer over-read in do_bid_note in readelf.c
CVE-2019-8906 - out-of-bounds read in do_core_note in readelf.c
* Mon Nov 05 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-8
- fix memory leak on an error path (#1602492)
* Thu Jan 31 2019 Fedora Release Engineering <releng@fedoraproject.org> - 5.35-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Jul 17 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-7
* Thu Jan 24 2019 Ondrej Dubaj <odubaj@redhat.com> - 5.35-4
- Added Linux PowerPC core offsets for Linux + fixed bug #1161911
* Thu Jan 24 2019 Ondrej Dubaj <odubaj@redhat.com> - 5.35-3
- Fixed bug missidentifying netpbm files (#856092)
* Tue Dec 04 2018 Ondrej Dubaj <odubaj@redhat.com> - 5.35-2
- Fixed bug misleading qcow2 v2 and v3 files (#1654349)
* Tue Dec 04 2018 Kamil Dudka <kdudka@redhat.com> - 5.35-1
- update to new version 5.35
* Wed Nov 21 2018 Ondrej Dubaj <odubaj@redhat.com> - 5.34-6
- Fixed missidentifying locale files bug (#1527398)
* Wed Nov 14 2018 Kamil Dudka <kdudka@redhat.com> - 5.34-5
- reintroduce the python2-magic subpackage needed by python2-bugzilla (#1649547)
* Mon Nov 12 2018 Kamil Dudka <kdudka@redhat.com> - 5.34-4
- add magic for eBPF objects (#1648667)
* Tue Jul 31 2018 Florian Weimer <fweimer@redhat.com> - 5.34-3
- Rebuild with fixed binutils
* Fri Jul 27 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 5.34-2
- Rebuild for new binutils
* Wed Jul 25 2018 Kamil Dudka <kdudka@redhat.com> - 5.34-1
- update to new version 5.34
* Tue Jul 17 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-10
- show details about ppc swap partition (#1224668)
- support longer version strings for clamav database (#1539107)
* Wed Jun 13 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-6
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 5.33-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Sun Jun 17 2018 Miro Hrončok <mhroncok@redhat.com> - 5.33-8
- Rebuilt for Python 3.7
* Wed Jun 13 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-7
- fix out-of-bounds read via a crafted ELF file (CVE-2018-10360)
* Mon May 28 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-6
- make file-devel depend on file-libs, instead of file
- reintroduce file-static subpackage (#1575661)
- drop obsolete Group tag
* Thu May 24 2018 Kamil Dudka <kdudka@redhat.com> - 5.33-5
- do not classify shared libraries as pie executables in MIME output (#1581343)

Loading…
Cancel
Save