summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2018-11-01 00:02:36 +0100
committerSebastian Rasmussen <sebras@gmail.com>2018-11-01 00:05:07 +0100
commit9b183c560ef9183f7d4ab32af56d8bad0b494f36 (patch)
tree03fad23e486095f2152704738416b966d05cf2db /source/fitz
parentcb530cdc26f5e04601f00140da02299b4b59a55b (diff)
downloadmupdf-9b183c560ef9183f7d4ab32af56d8bad0b494f36.tar.xz
Bug 700040: tar: Handle posix, ustar and v7 tar formats.
These formats are all almost identical to GNU tar format.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/untar.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/source/fitz/untar.c b/source/fitz/untar.c
index 9aac222b..1854dd41 100644
--- a/source/fitz/untar.c
+++ b/source/fitz/untar.c
@@ -85,7 +85,7 @@ static void ensure_tar_entries(fz_context *ctx, fz_tar_archive *tar)
blocks = (size + 511) / 512;
fz_seek(ctx, file, blocks * 512, 1);
- if (typeflag != '0')
+ if (typeflag != '0' && typeflag != '\0')
continue;
tar->entries = fz_resize_array(ctx, tar->entries, tar->count + 1, sizeof *tar->entries);
@@ -174,18 +174,24 @@ static int count_tar_entries(fz_context *ctx, fz_archive *arch)
int
fz_is_tar_archive(fz_context *ctx, fz_stream *file)
{
- const unsigned char signature[6] = { 'u', 's', 't', 'a', 'r', ' ' };
+ const unsigned char gnusignature[6] = { 'u', 's', 't', 'a', 'r', ' ' };
+ const unsigned char paxsignature[6] = { 'u', 's', 't', 'a', 'r', '\0' };
+ const unsigned char v7signature[6] = { '\0', '\0', '\0', '\0', '\0', '\0' };
unsigned char data[6];
size_t n;
fz_seek(ctx, file, 257, 0);
n = fz_read(ctx, file, data, nelem(data));
- if (n != nelem(signature))
+ if (n != nelem(data))
return 0;
- if (memcmp(data, signature, nelem(signature)))
- return 0;
-
- return 1;
+ if (!memcmp(data, gnusignature, nelem(gnusignature)))
+ return 1;
+ if (!memcmp(data, paxsignature, nelem(paxsignature)))
+ return 1;
+ if (!memcmp(data, v7signature, nelem(v7signature)))
+ return 1;
+
+ return 0;
}
fz_archive *