# Checksum incorrectly uses signed values

3 messages from 2012-06-14 to 2012-06-14. Participants: Brendan Brewster, Tomas Carnecky.
Thread: https://gitlist.dev/t/30801

## Brendan Brewster, 2012-06-14 01:16

Subject: Checksum incorrectly uses signed values
Message-ID: <CA+-ctj5M4XraOQJfWRVVFmRrNsUZUJyt63_Oi__OJCcYMC=ciw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2B-ctj5M4XraOQJfWRVVFmRrNsUZUJyt63_Oi__OJCcYMC%3Dciw%40mail.gmail.com

```
Hi,

I initially reported this issue to another developer thinking the
issue resided there but after some testing and discussion, have found
that the issue is not there but possibly here :)

The issue, in summary, is that 7-zip was unable to untar a tar created
via a "git archive" whereas gnu tar can. It seem that it may be the
case that git is incorrectly using signed values when creating the
checksum.

As Igor commented in the other aforementioned thread, "[t]hey use
'char' (that is 'signed char' by default in most compilers). BUT
correct TAR must use sum of unsigned values."

Please see the following:

1) The thread previously opened with Igor/7-Zip:
http://sourceforge.net/projects/sevenzip/forums/forum/45798/topic/5322604
2) http://www.gnu.org/software/tar/manual/html_node/Checksumming.html
3) TAR source code:
     tar_checksum
      and
     simple_finish_header
      functions.
4) GIT source code that calculates checksum: ustar_header_chksum
function in archive-tar.c. For reference, here is the snippet of the
git source code in question:

git-git-f623ca1\archive-tar.c
static unsigned int ustar_header_chksum(const struct ustar_header *header)
{
       const char *p = (const char *)header;
       unsigned int chksum = 0;
       while (p < header->chksum)
               chksum += *p++;
       chksum += sizeof(header->chksum) * ' ';
       p += sizeof(header->chksum);
       while (p < (const char *)header + sizeof(struct ustar_header))
               chksum += *p++;
       return chksum;
}

Can someone please look into this and possibly redirect if needed?

Thanks,
Brendan

```

## Tomas Carnecky, 2012-06-14 04:35

Subject: Re: Checksum incorrectly uses signed values
Message-ID: <1339648521-ner-3801@calvin>
URL: https://gitlist.dev/e/1339648521-ner-3801%40calvin
In-Reply-To: <CA+-ctj5M4XraOQJfWRVVFmRrNsUZUJyt63_Oi__OJCcYMC=ciw@mail.gmail.com>

```
On Wed, 13 Jun 2012 21:16:21 -0400, Brendan Brewster <brendan.brewster@gmail.com> wrote:
> Hi,
> 
> The issue, in summary, is that 7-zip was unable to untar a tar created
> via a "git archive" whereas gnu tar can. It seem that it may be the
> case that git is incorrectly using signed values when creating the
> checksum.
> 
> Can someone please look into this and possibly redirect if needed?

That was reported a day ago and Junio already wrote a patch. See
http://article.gmane.org/gmane.comp.version-control.git/199911.

tom

```

## Brendan Brewster, 2012-06-14 14:50

Subject: Re: Checksum incorrectly uses signed values
Message-ID: <CA+-ctj5tXQmeHcZ5CC74O5QSyOH1sEYTSL-f3Rcc4MtqmGnTgA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2B-ctj5tXQmeHcZ5CC74O5QSyOH1sEYTSL-f3Rcc4MtqmGnTgA%40mail.gmail.com
In-Reply-To: <CA+-ctj7v2v+=Sa2A+wSieXp26Q4wgVrTJnwyCt_erfPBmpdcdA@mail.gmail.com>

```
On Thu, Jun 14, 2012 at 12:39 AM, Brendan Brewster
<brendan.brewster@gmail.com> wrote:
> Hi Tomas/Junio,
>
> Yes, that is definitely it. The referenced 7-zip thread was my own
> that I tried to report today; I guess that's what I get for going on
> vacation and not getting a chance to submit my report here until after
> getting back :)
>
> Thanks, this is good news. I will report back to Igor on this.
>
> Thanks again,
> Brendan
>
> On Thu, Jun 14, 2012 at 12:35 AM, Tomas Carnecky
> <tomas.carnecky@gmail.com> wrote:
>> On Wed, 13 Jun 2012 21:16:21 -0400, Brendan Brewster <brendan.brewster@gmail.com> wrote:
>>> Hi,
>>>
>>> The issue, in summary, is that 7-zip was unable to untar a tar created
>>> via a "git archive" whereas gnu tar can. It seem that it may be the
>>> case that git is incorrectly using signed values when creating the
>>> checksum.
>>>
>>> Can someone please look into this and possibly redirect if needed?
>>
>> That was reported a day ago and Junio already wrote a patch. See
>> http://article.gmane.org/gmane.comp.version-control.git/199911.
>>
>> tom

Pushing this to the mailing list (sorry for the top post initially).

-Brendan

```
