sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit deb8a16527b235840fd04787463590ccf5198d07
parent 29649762b3602f4ce54ca8bb282524e5f1a92b92
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri,  8 May 2015 22:01:37 +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

Diffstat:
Mtar.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 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));