[PATCH] erofs-utils: lib: tar: allow pax headers with empty names
Gao Xiang
hsiangkao at linux.alibaba.com
Mon Sep 9 19:33:54 AEST 2024
Usually, `exthdr.name`s are set as "%d/PaxHeaders.%p/%f" [1].
However, since both `GNU tar` and `bsdtar` can process empty
`exthdr.name`s, let's allow them too.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html
Reported-by: Colin Walters <walters at verbum.org>
Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
lib/tar.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/lib/tar.c b/lib/tar.c
index 7e89b92..6d35292 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -283,9 +283,9 @@ static long long tarerofs_otoi(const char *ptr, int len)
inp[len] = '\0';
errno = 0;
- val = strtol(ptr, &endp, 8);
- if ((!val && endp == inp) |
- (*endp && *endp != ' '))
+ val = strtol(inp, &endp, 8);
+ if ((*endp == '\0' && endp == inp) |
+ (*endp != '\0' && *endp != ' '))
errno = EINVAL;
return val;
}
@@ -663,18 +663,19 @@ restart:
goto out;
}
tar->offset += sizeof(*th);
- if (*th->name == '\0') {
- if (e) { /* end of tar 2 empty blocks */
- ret = 1;
- goto out;
- }
- e = true; /* empty jump to next block */
- goto restart;
- }
/* chksum field itself treated as ' ' */
csum = tarerofs_otoi(th->chksum, sizeof(th->chksum));
if (errno) {
+ if (*th->name == '\0') {
+out_eot:
+ if (e) { /* end of tar 2 empty blocks */
+ ret = 1;
+ goto out;
+ }
+ e = true; /* empty jump to next block */
+ goto restart;
+ }
erofs_err("invalid chksum @ %llu", tar_offset);
ret = -EBADMSG;
goto out;
@@ -692,6 +693,11 @@ restart:
ckksum += (int)((char*)th)[j];
}
if (!tar->ddtaridx_mode && csum != cksum && csum != ckksum) {
+ /* should not bail out here, just in case */
+ if (*th->name == '\0') {
+ DBG_BUGON(1);
+ goto out_eot;
+ }
erofs_err("chksum mismatch @ %llu", tar_offset);
ret = -EBADMSG;
goto out;
--
2.43.5
More information about the Linux-erofs
mailing list