From: "Rafał Mużyło" <galtgendo@gmail.com>
To: git@vger.kernel.org
Subject: A slight inconvenience with 'git archive --format=tar'
Date: Wed, 13 Jun 2012 16:47:58 +0200 [thread overview]
Message-ID: <20120613144758.GA2438@blackspire> (raw)
[-- Attachment #1: Type: text/plain, Size: 501 bytes --]
I just stumbled upon this while checking a few mailing lists.
I haven't found any mails about in in the archives yet, so I assume, that
no mail have been written yet.
The problem is described here:
http://sourceforge.net/projects/sevenzip/forums/forum/45798/topic/5322604
Basically, while this is not a problem for GNU tar, the correct checksum
should be computed using unsigned values.
Attached trivial testcase shows the difference.
Patch making the change shown in the testcase also attached.
[-- Attachment #2: cksum-test.c --]
[-- Type: text/x-c, Size: 520 bytes --]
#include <stdio.h>
#include <string.h>
static unsigned int ustar_header_chksum(const void *buffer, int sign)
{
const char *p = (const char *)buffer;
unsigned int chksum = 0;
while (p < (const char *)buffer + strlen(buffer))
{
if (sign) chksum += *p++; else chksum += (unsigned char)*p++;
}
return chksum;
}
int main(int argc, char** argv)
{
const char* teststring = "żółte źrebię";
printf("%u\n", ustar_header_chksum(teststring, 0));
printf("%u\n", ustar_header_chksum(teststring, 1));
return 0;
}
[-- Attachment #3: git-tar.patch --]
[-- Type: text/plain, Size: 515 bytes --]
--- archive-tar.c 2012-04-26 21:25:49.000000000 +0200
+++ archive-tar.c 2012-06-13 16:43:59.220945967 +0200
@@ -104,11 +104,11 @@ static unsigned int ustar_header_chksum(
char *p = (char *)header;
unsigned int chksum = 0;
while (p < header->chksum)
- chksum += *p++;
+ chksum += (unsigned char)*p++;
chksum += sizeof(header->chksum) * ' ';
p += sizeof(header->chksum);
while (p < (char *)header + sizeof(struct ustar_header))
- chksum += *p++;
+ chksum += (unsigned char)*p++;
return chksum;
}
next reply other threads:[~2012-06-13 14:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-13 14:47 Rafał Mużyło [this message]
2012-06-13 17:45 ` A slight inconvenience with 'git archive --format=tar' Junio C Hamano
2012-06-13 19:58 ` René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120613144758.GA2438@blackspire \
--to=galtgendo@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).