Compare commits
No commits in common. 'cs10' and 'c9' have entirely different histories.
@ -1 +1 @@
|
||||
e8ee39339e5d3d68b7da9c45580f2ca5faf0db54 SOURCES/file-5.45.tar.gz
|
||||
a5a8941a8e4c436fe22933db6a71c5161c3fb10b SOURCES/file-5.39.tar.gz
|
||||
|
@ -1 +1 @@
|
||||
SOURCES/file-5.45.tar.gz
|
||||
SOURCES/file-5.39.tar.gz
|
||||
|
@ -1,79 +0,0 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: GnuPG v2
|
||||
|
||||
mQGiBEg60Q8RBAC89+Oyi+iU1dMftAqXKh9Ml2PDCRk+Q6gwSY2BwmnKrPYvLSx9/YApjDp4
|
||||
BzhjaMCiDtDkbVDO3JuLQqUsCUWRJr9UxgfkQPMx3obkgoyCCvUcG5eK9CHeztjz5UK3jOzD
|
||||
939UtupUXs+5z4dK1oAFFEL3sV6m5O4cuHyeWpjLCwCg9LYwmG2wIB65/2619W2kRMShDwkD
|
||||
/1KweB5mmXdQCDpzSg02Q4kGOzWmN2Dpv5kvKd9Lj/qxkj5PFOJ56Rmm04K0lPE6AnDgvEeu
|
||||
SqO8pkA8OY5IQNIjlgg3tshoMBRdsj9JLKv67smQXy01eQmadJWoiIZFuSLX7nrRLm3x3i1K
|
||||
4/tcKorXoD5QBgOWaYFzkOcQ5jrwA/9tn0MEkkVqez88xGhOjq6jooRWrP2lhNWb+Q7ayEvW
|
||||
9Wm9CYS0dXxlCCJfqBOc+cZo8iVVbqiOzwAQ7uAAUv8azuaeRWpOD7MSjkXjYtkPwZevEd6x
|
||||
FKODaB2BDO4WMlxO9mp3Q/gPfrM41v9n33tYsAzQMW7c9W5mX/XH2Cv/57QyQ2hyaXN0b3Mg
|
||||
Wm91bGFzIChOZXRCU0Qga2V5KSA8Y2hyaXN0b3NAbmV0YnNkLm9yZz6IXgQQEQgABgUCWcg8
|
||||
UAAKCRCWb7A7gPrCzP43AP9pxzM85lwZxHRG8vPw16wWUYGcGW44g/u1zqavRUksvgD/fX1y
|
||||
6+cj5kNEqp5bHgCvOJiSYADIUQaPTYbwMvnQ1IuIZAQTEQIAJAIbAwYLCQgHAwIDFQIDAxYC
|
||||
AQIeAQIXgAUCV7RsLgUJIkWeFwAKCRBxESqxbLM7Oi/LAKC1PdNLcoP06p6nsGh4ApH0gkSl
|
||||
fgCg7k7lwLPdN0djOMUPMFnqN+TYAoaIZAQTEQIAJAUCSDrTKgIbAwUJDwmcAAYLCQgHAwID
|
||||
FQIDAxYCAQIeAQIXgAAKCRBxESqxbLM7OqXeAJ9tkhVpTsdkix5oWzsBCbU4vHO2CACfbd8k
|
||||
PWR68VgvDK5RPQchyghfIZGJARwEEAECAAYFAlnOXIQACgkQWrHF/qWWAmTEhggAmTr9PxSU
|
||||
wQ8dAvno6I30mDY+r4V2FaD+WvhITDV/CYfU4ImDCfknDC1x4f44YAgN94YQfnTmAixWLLk9
|
||||
NhvgKWHg5Sq2p7S3hLe3hQHUu+4mHq2t+oBtiwnb+GPUAz3ko1hjQ2fN3nZdwKNA3P37NJuj
|
||||
EiXOR1UsxO8TaTuf/mB+9vdrUpHsgRaZwYIJ7oszkRkr2V82QsMwgcIdnCPEVY7q+foi2DUF
|
||||
UW3eujRLpW9M/NUXrA8f2wQZVaLNy+Zpai57uXW7bVRc82+uRDVwckhKq+YRpfRiD/JCWzKP
|
||||
AJJfabUkKiA6NUe51aQJm64BUKh7p8ZR4qjCr/Roofsh9okCHAQQAQIABgUCWduxXQAKCRBm
|
||||
Bw6ljCki37ulD/4iZ9hjimgichG5F5Ht2CfPx3Qm16QYjnuB2l7FZNPYlcThdNgjJjc4Wro3
|
||||
jrcfj6KMTGXnkRuY7794co6z/U/x9sVz9wQYr0ugrJsVQeHRWbJGl2vFhOOtgj9hfJQM44nz
|
||||
3ZZR4VDh/KU4njBhPR1Mzxoop1WBnWcE9RpTIyMlaB6RK9I8JGOpvNYzQaODnsG7z144G/3W
|
||||
gIWZnjVVozv/szvtabd+L1N3hMPI2jNkmKWSGuZWdIIcPBEp2e9AYmb9mVhp8UanrMWVTUi0
|
||||
q7Cc0Jw4tkTwXYaEeRcbbB87p+IV0an7o+m9e2hrdZJan276tDOFe+HgcZ4NiEM8LTcOBIHn
|
||||
VWaRLwQD4AAB8zmMHiVTN3oUdQsYlZmHhBYv8Bkfzwi8JdxMq7V2zGntQnROl9Ust3qL8g28
|
||||
xI/dzt396qupywaF/2bUKyZx/079Y3eEluPQlU+iof+hJ2roetJNwMzs/hTDLQgI4T8ZhsMO
|
||||
MewZUVI59YrqjETR1U6+L9txmULgL16jBpLqvFBGhUOIDqjI5uxapEjCGy3inocjUeejy5iN
|
||||
PehQwt2TKC2Exsyd02kJrPErYVcMLYbO90d2ykBItoSXsDcuOTgfyxpvxTUih4tHVf5B69Ht
|
||||
HAPPYqSEfwlVazLnoe/z5KU2h415vcwuRuI1WU0ghdGFCMmH1rQ0Q2hyaXN0b3MgWm91bGFz
|
||||
IChwZXJzb25hbCBrZXkpIDxjaHJpc3Rvc0B6b3VsYXMuY29tPoheBBARCAAGBQJZyDxEAAoJ
|
||||
EJZvsDuA+sLMa3oA/Rub7s6Vp61CJ4kDTyfAJg0vL2Y6dqb0l1qZfg7kHWDTAQDK85IGzegN
|
||||
dAftzh5ZBgOOByQ8C8nprbxQWNTKXwWBH4hkBBMRAgAkAhsDBgsJCAcDAgMVAgMDFgIBAh4B
|
||||
AheABQJXtGwxBQkiRZ4XAAoJEHERKrFsszs6XGUAn2mngFtwV1va2adBDUrx4ZpXHQNBAJ9w
|
||||
EZ8bIqAmyTrAE8r0iOXe1bzWrIhkBBMRAgAkBQJIOtEPAhsDBQkPCZwABgsJCAcDAgMVAgMD
|
||||
FgIBAh4BAheAAAoJEHERKrFsszs63YcAnRjURIBsnyKeY+f6jO8pVYx499LHAJwP4h+X2i+r
|
||||
drCNiSYYVCYbkNjysokBHAQQAQIABgUCWc5chAAKCRBascX+pZYCZA6bCACAB7DFdL0DfXUU
|
||||
+BTcJQXvlD9fKBoGmonUACPX/wq7phmnvJL0Btl1KJlcLuiu94PgLPXH4nWwpGnWG2Ogigqf
|
||||
HxM4Jx6skqkBQI6npacTU1nSaIBW4hKZpo/6QvgjmO1wsSPemIvZ/8+ijfS5AHPh0gew3BFj
|
||||
ESPvwWxxode3zDKD5n6g1vU4Id9i0OqjUUkUnCBy8pz6b/n3VuyYXM+OnMgZw+tXfYUJkf3v
|
||||
15gWhXlmpeLCPdmSZ8NRy80lrY45EHra2lPx3RgX88AF3cgwLrKfjLRc1yuSZ1mipT+pI1Fs
|
||||
uUe14XfXHiLM2ESp2HLDLmCY8lwYelmWPO76skwEiQIcBBABAgAGBQJZ27FdAAoJEGYHDqWM
|
||||
KSLft9UP/3ZxzMkr2m8/itBLOBJbMlvCb5gfZLHrQV/GF9OIDDSdu0+4cbbVqeXyg4tEQHHi
|
||||
8Gr9WZI3CgqWbJN66NkKnaPqZ4RE7a98h9AvRxWsGhBI+I8r8LTlsQQrhjUyEinsr7oqNP9M
|
||||
SO7vicg6df5SuWmQxTrap8A1noX6O0djzJ9Ea721hCHDxGQ9nxCAPOIvS7lI06soNLuuTdp+
|
||||
E+r1d3+saHGU6YK8GsnqFSTdxb9WBUJU8BQpcI9kL3iIGA8Azw6L5CFra9InCCQIjzHIbL/r
|
||||
WLIJKxJicHJib009atUeLDCwmdaLHoqOkqOJIYrnbbEkPQunY6A68KkNx05N5p46eRwKxKA0
|
||||
TJQAMyzdkCYKaiQe+pETwsyO89P9RK84P5wCG4jqSe29JW7VeuBOQDJ3khBN3whDu9s5gVlh
|
||||
UGjIeLo85g7IIKTtv5fbopAUCjbVwccqws54PmiSqTy5OlOCbbYGDtoermnXME+sFcNRT8MI
|
||||
ktWShC6GrF1BhVrS4ex9e6jsQxKQRMlab2bBeJ6rUXT/i8cnpJERViPspDvVgL7Oer+K2gep
|
||||
uNa2DeCaNardaAYo2IYu985pqRZYJVTCydmX+Wlhfp12tzToW1/9QsLTvKUhuI0WB/cC839t
|
||||
lJRXapfKjwjj91VEX7Y26vHWli5noHMSNIRlIjT5RqouuQQNBEg60jMQEADIcUV/L4XmXXqj
|
||||
GvglW2ZAPn/FIm+N4GM/vTjxUXAc2ciiIsTDuO+1+e4sB9eN05rcvtTyt28W6N6hL8HfQIFq
|
||||
5WEsd86vd+cSiBlisq1BglNgFiAfRy/guoLHiYnBlSdS6/Gab86zR4m6Bg1JZOcV0c9Irffv
|
||||
5XLlT/LX45V46ju3PQSJYGboKdEaX4jUWcSQgUQ4+HyyP2DsWPyfrJj4sFA0T78b1ywsyKK2
|
||||
OOv7KUQk/Hwq2C68aG6YlvvVKywucoSX2uk0ZnWjCCwgOtXxyHIysqAxcz9IPRbtJ3PjjScM
|
||||
kv9NMrb5SDswwZy1vfL8s1sa8w7uZgXlpOaFb/yYMuzvwKRwJNxptVW0TTcZ8ADemRiHgDzJ
|
||||
0MbXYcmSH8CXla746Bg7oXaCMPvfivOnIsj/6d3YZPT1enwBprgL3VqlWPA4fjWyMh6+BoHu
|
||||
ak7Q4k2h2sSXo29tR6KXYbc+K+qUB+QrjGDkOL6JqN5nBLiu3H95B7ZEm8wDoYitDpt7ot9S
|
||||
5ja+dcNyUu+XXUGXvc8SvzEmsDKMqxZSxvCyIfPhaFxVylLK02fhfXqpBImvZ6UmHOzylNlk
|
||||
TqJzDG4LOOiC/knv7ypgr7VH8TJ2PD9p2IR79hKjnVGmYvTtZ132qda+erbNb/9wwAzOeG49
|
||||
fgdiDSsUmvl15kEI+gBtZwADBQ/+PuZa9CEKryZpQ6hczzAN8oksk7MQaTBYdAd62zfaNa/Q
|
||||
QID3P5I8FsdXMCcKRipP95cZY8ZQKjBGt7O26Ts955Q71QS58rCXxeLP9/mbpm3kCwXrAkZH
|
||||
s2rH2awLOg6p8at2NJCn56AkldK1PyVtL0Qvl7nEOe+lcULqfLNEbGEgzev+ZK0v6So6lA2t
|
||||
i8derF5XkIMzCFdjcC1reZvfwNnxd/pQzuMfZOfPjPD6OKaBEWnWNZscU/ucNkgQpv+M2hCA
|
||||
paC3NaNiXl0TWsDp7981WSWnf6YZRTjLKyObdGmpo7Z+C9uVu2DbRlUiRAD3azBo4t03EZVB
|
||||
XMo/1opuqxyU6FLVW0mxLI2wh2M1Jt/RAvXLm5/Z9zGnPqwAObxkA518e71QXyM+GQ+M8Kyp
|
||||
PHr00oC+32PrKnFADI3s1oK5zMX0tjXb0voAgXTWNFsmi+efj7A3wt6G15ai70pOSTuFl9kb
|
||||
BqmCI4NmD5wV+uIR/jcmTf7jZKX5QPjDSJddJ5EeAsPXtur0wFZ9JwPM2FyNaeL92BjRYQPW
|
||||
C9vRtAUjJa2PSLofMDaEs+VD76WRI3E8kPIJiFeSqOLinclo1e41q3nyj5JBnwg50CwshW7g
|
||||
w/bU+IbzL0eZFjJ7ftJ+Xi/vlGtfbxjuKuhyD2PM3DNf9uXmcIV4ldEJzwhw2KmITwQYEQIA
|
||||
DwIbDAUCV7RsRgUJIkWdEAAKCRBxESqxbLM7OiJUAJ4y0+A//pOrp3rjo28Uyt34U+qRqwCe
|
||||
NqiZtKbSqpUgcLmKNgot+mSEAmmITwQYEQIADwUCSDrSMwIbDAUJDwmcAAAKCRBxESqxbLM7
|
||||
OnaqAJ0cUAs8+EPXqRYYbdu6ROINhExMkwCgpupi6uEG+b4yo6M+VlcQY7gl2DE=
|
||||
=XrDo
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
@ -0,0 +1,45 @@
|
||||
diff --git a/src/compress.c b/src/compress.c
|
||||
index ba1e3d7..6846d66 100644
|
||||
--- a/src/compress.c
|
||||
+++ b/src/compress.c
|
||||
@@ -932,23 +932,23 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
|
||||
rv = OKDATA;
|
||||
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");
|
||||
-
|
||||
- rv = ERRDATA;
|
||||
- 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],
|
||||
+ strerror(errno));
|
||||
+ goto err;
|
||||
+ } else if ((r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0){
|
||||
+ rv = ERRDATA;
|
||||
+ 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;
|
||||
}
|
||||
ok:
|
||||
*n = r;
|
@ -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) {
|
@ -0,0 +1,77 @@
|
||||
diff --git a/src/Makefile.am b/src/Makefile.am
|
||||
index b43cb8e..93d6625 100644
|
||||
--- a/src/Makefile.am
|
||||
+++ b/src/Makefile.am
|
||||
@@ -17,10 +17,10 @@ MINGWLIBS = -lgnurx -lshlwapi
|
||||
else
|
||||
MINGWLIBS =
|
||||
endif
|
||||
-libmagic_la_LIBADD = $(LTLIBOBJS) $(MINGWLIBS)
|
||||
+libmagic_la_LIBADD = -lm $(LTLIBOBJS) $(MINGWLIBS)
|
||||
|
||||
file_SOURCES = file.c seccomp.c
|
||||
-file_LDADD = libmagic.la
|
||||
+file_LDADD = libmagic.la -lm
|
||||
CLEANFILES = magic.h
|
||||
EXTRA_DIST = magic.h.in
|
||||
HDR= $(top_srcdir)/src/magic.h.in
|
||||
diff --git a/src/softmagic.c b/src/softmagic.c
|
||||
index becc53c..39c7e0b 100644
|
||||
--- a/src/softmagic.c
|
||||
+++ b/src/softmagic.c
|
||||
@@ -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>
|
||||
+#include <math.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
@@ -2074,19 +2075,19 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
|
||||
break;
|
||||
|
||||
case '!':
|
||||
- matched = fv != fl;
|
||||
+ matched = isunordered(fl, fv) ? 1 : fv != fl;
|
||||
break;
|
||||
|
||||
case '=':
|
||||
- matched = fv == fl;
|
||||
+ matched = isunordered(fl, fv) ? 0 : fv == fl;
|
||||
break;
|
||||
|
||||
case '>':
|
||||
- matched = fv > fl;
|
||||
+ matched = isgreater(fv, fl);
|
||||
break;
|
||||
|
||||
case '<':
|
||||
- matched = fv < fl;
|
||||
+ matched = isless(fv, fl);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2107,19 +2108,19 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache)
|
||||
break;
|
||||
|
||||
case '!':
|
||||
- matched = dv != dl;
|
||||
+ matched = isunordered(dv, dl) ? 1 : dv != dl;
|
||||
break;
|
||||
|
||||
case '=':
|
||||
- matched = dv == dl;
|
||||
+ matched = isunordered(dv, dl) ? 0 : dv == dl;
|
||||
break;
|
||||
|
||||
case '>':
|
||||
- matched = dv > dl;
|
||||
+ matched = isgreater(dv, dl);
|
||||
break;
|
||||
|
||||
case '<':
|
||||
- matched = dv < dl;
|
||||
+ matched = isless(dv, dl);
|
||||
break;
|
||||
|
||||
default:
|
@ -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
|
@ -0,0 +1,130 @@
|
||||
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.
|
||||
|
||||
---
|
||||
src/readelf.c | 37 ++++++++++++++++++++++++++-----------
|
||||
1 file changed, 26 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/src/readelf.c b/src/readelf.c
|
||||
index cf1dc91b7..d390d5f6a 100644
|
||||
--- a/src/readelf.c
|
||||
+++ b/src/readelf.c
|
||||
@@ -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,
|
||||
- int clazz, int swap)
|
||||
+ int clazz, int swap, int *pie, size_t *need)
|
||||
{
|
||||
Elf32_Dyn dh32;
|
||||
Elf64_Dyn dh64;
|
||||
@@ -1117,11 +1117,15 @@ dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
|
||||
|
||||
switch (xdh_tag) {
|
||||
case DT_FLAGS_1:
|
||||
+ *pie = 1;
|
||||
if (xdh_val & DF_1_PIE)
|
||||
ms->mode |= 0111;
|
||||
else
|
||||
ms->mode &= ~0111;
|
||||
break;
|
||||
+ case DT_NEEDED:
|
||||
+ (*need)++;
|
||||
+ break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1608,9 +1612,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
||||
}
|
||||
|
||||
/*
|
||||
- * Look through the program headers of an executable image, searching
|
||||
- * for a PT_INTERP section; if one is found, it's dynamically linked,
|
||||
- * otherwise it's statically linked.
|
||||
+ * Look through the program headers of an executable image, to determine
|
||||
+ * if it is statically or dynamically linked. If it has a dynamic section,
|
||||
+ * it is pie, and does not have an interpreter or needed libraries, we
|
||||
+ * call it static pie.
|
||||
*/
|
||||
private int
|
||||
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;
|
||||
- const char *linking_style = "statically";
|
||||
+ const char *linking_style;
|
||||
unsigned char nbuf[BUFSIZ];
|
||||
char ibuf[BUFSIZ];
|
||||
char interp[BUFSIZ];
|
||||
ssize_t bufsize;
|
||||
- size_t offset, align, len;
|
||||
+ size_t offset, align, len, need = 0;
|
||||
+ int pie = 0, dynamic = 0;
|
||||
|
||||
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:
|
||||
doread = 1;
|
||||
- linking_style = "dynamically";
|
||||
break;
|
||||
case PT_NOTE:
|
||||
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:
|
||||
+ dynamic = 1;
|
||||
offset = 0;
|
||||
// Let DF_1 determine if we are PIE or not.
|
||||
ms->mode &= ~0111;
|
||||
@@ -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);
|
||||
+ CAST(size_t, bufsize), clazz, swap,
|
||||
+ &pie, &need);
|
||||
if (offset == 0)
|
||||
break;
|
||||
}
|
||||
@@ -1710,6 +1717,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
|
||||
break;
|
||||
|
||||
case PT_INTERP:
|
||||
+ need++;
|
||||
if (ms->flags & MAGIC_MIME)
|
||||
continue;
|
||||
if (bufsize && nbuf[0]) {
|
||||
@@ -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;
|
||||
- if (file_printf(ms, ", %s linked", linking_style)
|
||||
- == -1)
|
||||
+ if (dynamic) {
|
||||
+ if (pie && need == 0)
|
||||
+ linking_style = "static-pie";
|
||||
+ else
|
||||
+ linking_style = "dynamically";
|
||||
+ } else {
|
||||
+ linking_style = "statically";
|
||||
+ }
|
||||
+ if (file_printf(ms, ", %s linked", linking_style) == -1)
|
||||
return -1;
|
||||
if (interp[0])
|
||||
if (file_printf(ms, ", interpreter %s",
|
@ -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,103 +0,0 @@
|
||||
diff --git a/doc/file.man b/doc/file.man
|
||||
index bf78c0c..a0a363c 100644
|
||||
--- a/doc/file.man
|
||||
+++ b/doc/file.man
|
||||
@@ -340,12 +340,12 @@ never read them.
|
||||
.It Fl P , Fl Fl parameter Ar name=value
|
||||
Set various parameter limits.
|
||||
.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
+.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
|
||||
.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
|
||||
.It Li bytes Ta 1M Ta max number of bytes to read from file
|
||||
.It Li elf_notes Ta 256 Ta max ELF notes processed
|
||||
.It Li elf_phnum Ta 2K Ta max ELF program sections processed
|
||||
.It Li elf_shnum Ta 32K Ta max ELF sections processed
|
||||
-.It Li elf_shsize Ta 128MB Ta max ELF section size processed
|
||||
.It Li encoding Ta 65K Ta max number of bytes to determine encoding
|
||||
.It Li indir Ta 50 Ta recursion limit for indirect magic
|
||||
.It Li name Ta 50 Ta use count limit for name/use magic
|
||||
diff --git a/src/apprentice.c b/src/apprentice.c
|
||||
index 7907841..1d862df 100644
|
||||
--- a/src/apprentice.c
|
||||
+++ b/src/apprentice.c
|
||||
@@ -577,7 +577,6 @@ file_ms_alloc(int flags)
|
||||
ms->indir_max = FILE_INDIR_MAX;
|
||||
ms->name_max = FILE_NAME_MAX;
|
||||
ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
|
||||
- ms->elf_shsize_max = FILE_ELF_SHSIZE_MAX;
|
||||
ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
|
||||
ms->elf_notes_max = FILE_ELF_NOTES_MAX;
|
||||
ms->regex_max = FILE_REGEX_MAX;
|
||||
diff --git a/src/file.c b/src/file.c
|
||||
index 31c1035..4fa275c 100644
|
||||
--- a/src/file.c
|
||||
+++ b/src/file.c
|
||||
@@ -156,8 +156,6 @@ file_private struct {
|
||||
MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
|
||||
{ "elf_shnum", 0, FILE_ELF_SHNUM_MAX, "max ELF sections processed",
|
||||
MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
|
||||
- { "elf_shsize", 0, FILE_ELF_SHSIZE_MAX, "max ELF section size",
|
||||
- MAGIC_PARAM_ELF_SHSIZE_MAX, 0 },
|
||||
{ "encoding", 0, FILE_ENCODING_MAX, "max bytes to scan for encoding",
|
||||
MAGIC_PARAM_ENCODING_MAX, 0 },
|
||||
{ "indir", 0, FILE_INDIR_MAX, "recursion limit for indirection",
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 78f574e..049ef3c 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -492,14 +492,12 @@ struct magic_set {
|
||||
uint16_t regex_max;
|
||||
size_t bytes_max; /* number of bytes to read from file */
|
||||
size_t encoding_max; /* bytes to look for encoding */
|
||||
- size_t elf_shsize_max;
|
||||
#ifndef FILE_BYTES_MAX
|
||||
# define FILE_BYTES_MAX (7 * 1024 * 1024)/* how much of the file to look at */
|
||||
#endif /* above 0x6ab0f4 map offset for HelveticaNeue.dfont */
|
||||
#define FILE_ELF_NOTES_MAX 256
|
||||
#define FILE_ELF_PHNUM_MAX 2048
|
||||
#define FILE_ELF_SHNUM_MAX 32768
|
||||
-#define FILE_ELF_SHSIZE_MAX (128 * 1024 * 1024)
|
||||
#define FILE_INDIR_MAX 50
|
||||
#define FILE_NAME_MAX 50
|
||||
#define FILE_REGEX_MAX 8192
|
||||
diff --git a/src/magic.c b/src/magic.c
|
||||
index 052f997..5084dcc 100644
|
||||
--- a/src/magic.c
|
||||
+++ b/src/magic.c
|
||||
@@ -625,9 +625,6 @@ magic_setparam(struct magic_set *ms, int param, const void *val)
|
||||
case MAGIC_PARAM_ELF_SHNUM_MAX:
|
||||
ms->elf_shnum_max = CAST(uint16_t, *CAST(const size_t *, val));
|
||||
return 0;
|
||||
- case MAGIC_PARAM_ELF_SHSIZE_MAX:
|
||||
- ms->elf_shsize_max = *CAST(const size_t *, val);
|
||||
- return 0;
|
||||
case MAGIC_PARAM_ELF_NOTES_MAX:
|
||||
ms->elf_notes_max = CAST(uint16_t, *CAST(const size_t *, val));
|
||||
return 0;
|
||||
@@ -664,9 +661,6 @@ magic_getparam(struct magic_set *ms, int param, void *val)
|
||||
case MAGIC_PARAM_ELF_SHNUM_MAX:
|
||||
*CAST(size_t *, val) = ms->elf_shnum_max;
|
||||
return 0;
|
||||
- case MAGIC_PARAM_ELF_SHSIZE_MAX:
|
||||
- *CAST(size_t *, val) = ms->elf_shsize_max;
|
||||
- return 0;
|
||||
case MAGIC_PARAM_ELF_NOTES_MAX:
|
||||
*CAST(size_t *, val) = ms->elf_notes_max;
|
||||
return 0;
|
||||
diff --git a/src/readelf.c b/src/readelf.c
|
||||
index a2a66dd..71c0ad1 100644
|
||||
--- a/src/readelf.c
|
||||
+++ b/src/readelf.c
|
||||
@@ -1450,12 +1450,6 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
- if (xsh_size > ms->elf_shsize_max) {
|
||||
- file_error(ms, errno, "Note section size too "
|
||||
- "big (%ju > %zu)", (uintmax_t)xsh_size,
|
||||
- ms->elf_shsize_max);
|
||||
- return -1;
|
||||
- }
|
||||
if ((nbuf = malloc(xsh_size)) == NULL) {
|
||||
file_error(ms, errno, "Cannot allocate memory"
|
||||
" for note");
|
@ -1,36 +0,0 @@
|
||||
From 218fdf813fd5ccecbb8887a1b62509cd1c6dd3a1 Mon Sep 17 00:00:00 2001
|
||||
From: Christos Zoulas <christos@zoulas.com>
|
||||
Date: Fri, 28 Jul 2023 14:38:25 +0000
|
||||
Subject: [PATCH] deal with 32 bit time_t
|
||||
|
||||
---
|
||||
src/file.h | 8 +++++---
|
||||
1 file changed, 5 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 2e0494d2f..78f574ea1 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.247 2023/07/27 19:40:22 christos Exp $
|
||||
+ * @(#)$File: file.h,v 1.248 2023/07/28 14:38:25 christos Exp $
|
||||
*/
|
||||
|
||||
#ifndef __file_h__
|
||||
@@ -159,9 +159,11 @@
|
||||
/*
|
||||
* Dec 31, 23:59:59 9999
|
||||
* we need to make sure that we don't exceed 9999 because some libc
|
||||
- * implementations like muslc crash otherwise
|
||||
+ * implementations like muslc crash otherwise. If you are unlucky
|
||||
+ * to be running on a system with a 32 bit time_t, then it is even less.
|
||||
*/
|
||||
-#define MAX_CTIME CAST(time_t, 0x3afff487cfULL)
|
||||
+#define MAX_CTIME \
|
||||
+ CAST(time_t, sizeof(time_t) > 4 ? 0x3afff487cfULL : 0x7fffffffULL)
|
||||
|
||||
#define FILE_BADSIZE CAST(size_t, ~0ul)
|
||||
#define MAXDESC 64 /* max len of text description/MIME type */
|
@ -1,6 +0,0 @@
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iEYEABECAAYFAmTCz2IACgkQcREqsWyzOzpvCgCcDRR1icCs3FF4dXiIXCS3mykf
|
||||
T5wAoI4+RrEesZEWRBl641Z1lshkK+4c
|
||||
=bF1Y
|
||||
-----END PGP SIGNATURE-----
|
Loading…
Reference in new issue