From deb8a16527b235840fd04787463590ccf5198d07 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 8 May 2015 22:01:37 +0200 Subject: [PATCH] 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 --- tar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tar.c b/tar.c index 2162423..8c432d1 100644 --- a/tar.c +++ b/tar.c @@ -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); @@ -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));