summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2022-09-07 14:16:33 +0000
committerChristos Zoulas <christos@zoulas.com>2022-09-07 14:16:33 +0000
commit21fdda01618062f983d22f795e29cd240839b991 (patch)
tree1415e2fbd99cf0266637cce1a69e247b2e923b2a
parentb44fc3a12c7d6c98282eacc8b660ab6e21bc718c (diff)
downloadfile-git-21fdda01618062f983d22f795e29cd240839b991.tar.gz
Avoid detecting gpkg files as tar archives (Michal Gorny).
-rw-r--r--src/is_tar.c16
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/gpkg-1-zst.result1
-rw-r--r--tests/gpkg-1-zst.testfilebin0 -> 1024 bytes
4 files changed, 18 insertions, 1 deletions
diff --git a/src/is_tar.c b/src/is_tar.c
index 82b08051..ed2f520e 100644
--- a/src/is_tar.c
+++ b/src/is_tar.c
@@ -40,7 +40,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.44 2019/02/20 02:35:27 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.45 2022/09/07 14:16:33 christos Exp $")
#endif
#include "magic.h"
@@ -98,15 +98,29 @@ file_is_tar(struct magic_set *ms, const struct buffer *b)
private int
is_tar(const unsigned char *buf, size_t nbytes)
{
+ static const char gpkg_match[] = "/gpkg-1";
+
const union record *header = RCAST(const union record *,
RCAST(const void *, buf));
size_t i;
int sum, recsum;
const unsigned char *p, *ep;
+ const char *nulp;
if (nbytes < sizeof(*header))
return 0;
+ /* If the file looks like Gentoo GLEP 78 binary package (GPKG),
+ * don't waste time on further checks and fall back to magic rules.
+ */
+ nulp = memchr(header->header.name, 0, sizeof(header->header.name));
+ if (nulp != NULL && nulp >= header->header.name + sizeof(gpkg_match) &&
+ memcmp(nulp - sizeof(gpkg_match) + 1, gpkg_match,
+ sizeof(gpkg_match)) == 0) {
+ fprintf(stderr, "match\n");
+ return 0;
+ }
+
recsum = from_oct(header->header.chksum, sizeof(header->header.chksum));
sum = 0;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 22120a8b..0fa6aec2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,8 @@ fit-map-data.result \
fit-map-data.testfile \
gedcom.result \
gedcom.testfile \
+gpkg-1-zst.result \
+gpkg-1-zst.testfile \
hddrawcopytool.result \
hddrawcopytool.testfile \
issue311docx.result \
diff --git a/tests/gpkg-1-zst.result b/tests/gpkg-1-zst.result
new file mode 100644
index 00000000..af9a080e
--- /dev/null
+++ b/tests/gpkg-1-zst.result
@@ -0,0 +1 @@
+Gentoo GLEP 78 (GPKG) binary package using zstd compression \ No newline at end of file
diff --git a/tests/gpkg-1-zst.testfile b/tests/gpkg-1-zst.testfile
new file mode 100644
index 00000000..00c71c01
--- /dev/null
+++ b/tests/gpkg-1-zst.testfile
Binary files differ