git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Rafał Mużyło" <galtgendo@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: A slight inconvenience with 'git archive --format=tar'
Date: Wed, 13 Jun 2012 10:45:36 -0700	[thread overview]
Message-ID: <7vmx47gl6n.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20120613144758.GA2438@blackspire> (=?utf-8?B?IlJhZmHFgiBN?= =?utf-8?B?dcW8ecWCbyIncw==?= message of "Wed, 13 Jun 2012 16:47:58 +0200")

Rafał Mużyło <galtgendo@gmail.com> writes:

> 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

Thanks.  It sounds a bit more than "slight inconvenience" to me ;-)

-- >8 --
Date: Wed, 13 Jun 2012 10:42:25 -0700
Subject: [PATCH] archive: ustar header checksum is computed unsigned

POSIX.1 (pax) is pretty clear on this:

  The chksum field shall be the ISO/IEC 646:1991 standard IRV
  representation of the octal value of the simple sum of all octets
  in the header logical record. Each octet in the header shall be
  treated as an unsigned value. These values shall be added to an
  unsigned integer, initialized to zero, the precision of which is
  not less than 17 bits. When calculating the checksum, the chksum
  field is treated as if it were all <space> characters.

so is GNU:

  http://www.gnu.org/software/tar/manual/html_node/Checksumming.html

Found by 7zip folks and reported by Rafał Mużyło.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 archive-tar.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/archive-tar.c b/archive-tar.c
index dc91c6b..0ba3f25 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -139,13 +139,13 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
 
 static unsigned int ustar_header_chksum(const struct ustar_header *header)
 {
-	const char *p = (const char *)header;
+	const unsigned char *p = (const unsigned char *)header;
 	unsigned int chksum = 0;
-	while (p < header->chksum)
+	while (p < (const unsigned char *)header->chksum)
 		chksum += *p++;
 	chksum += sizeof(header->chksum) * ' ';
 	p += sizeof(header->chksum);
-	while (p < (const char *)header + sizeof(struct ustar_header))
+	while (p < (const unsigned char *)header + sizeof(struct ustar_header))
 		chksum += *p++;
 	return chksum;
 }
-- 
1.7.11.rc3.25.g4c2075b

  reply	other threads:[~2012-06-13 17:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13 14:47 A slight inconvenience with 'git archive --format=tar' Rafał Mużyło
2012-06-13 17:45 ` Junio C Hamano [this message]
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=7vmx47gl6n.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=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).