commit deb8a16527b235840fd04787463590ccf5198d07
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri May 8 22:01:37 2015 +0200
tar: fix checksum calculation (signed/unsigned issue)
some archives gave the error: "malformed tar archive"
test file where this occurred:
http://nl.alpinelinux.org/alpine/v3.1/main/x86_64/apk-tools-static-2.5.0_rc1-r0.apk
diff --git a/tar.c b/tar.c
index 2162423..8c432d1 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -237,7 +237,7 @@ archive(const char *path)
memset(h->chksum, ' ', sizeof(h->chksum));
for (i = 0, chksum = 0; i < sizeof(*h); i++)
- chksum += b[i];
+ chksum += (unsigned char)b[i];
putoctal(h->chksum, chksum, sizeof(h->chksum));
ewrite(tarfd, b, BLKSIZ);
_AT_@ -412,7 +412,7 @@ chktar(struct header *h)
goto bad;
memset(h->chksum, ' ', sizeof(h->chksum));
for (i = 0, s2 = 0; i < sizeof(*h); i++)
- s2 += p[i];
+ s2 += (unsigned char)p[i];
if (s1 != s2)
goto bad;
memcpy(h->chksum, tmp, sizeof(h->chksum));
Received on Fri May 08 2015 - 22:36:46 CEST