Skip to content

Commit a5a46eb

Browse files
committed
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 <[email protected]>
1 parent befc5ed commit a5a46eb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

archive-tar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
139139

140140
static unsigned int ustar_header_chksum(const struct ustar_header *header)
141141
{
142-
const char *p = (const char *)header;
142+
const unsigned char *p = (const unsigned char *)header;
143143
unsigned int chksum = 0;
144-
while (p < header->chksum)
144+
while (p < (const unsigned char *)header->chksum)
145145
chksum += *p++;
146146
chksum += sizeof(header->chksum) * ' ';
147147
p += sizeof(header->chksum);
148-
while (p < (const char *)header + sizeof(struct ustar_header))
148+
while (p < (const unsigned char *)header + sizeof(struct ustar_header))
149149
chksum += *p++;
150150
return chksum;
151151
}

0 commit comments

Comments
 (0)