Commit a5a46eb9 authored by Junio C Hamano's avatar Junio C Hamano

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:

Found by 7zip folks and reported by Rafał Mużyło.
Signed-off-by: default avatarJunio C Hamano <>
parent befc5ed3
......@@ -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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment