{"thread":{"id":"30794","subject":"A slight inconvenience with 'git archive --format=tar'","startedAt":"2012-06-13T14:47:58Z","lastAt":"2012-06-13T19:58:31Z","messageCount":3,"participants":["Rafał Mużyło","Junio C Hamano","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"193542","messageId":"20120613144758.GA2438@blackspire","threadId":"30794","inReplyTo":null,"subject":"A slight inconvenience with 'git archive --format=tar'","fromName":"Rafał Mużyło","fromEmail":"galtgendo@gmail.com","sentAt":"2012-06-13T14:47:58Z","receivedAt":"2012-06-13T14:47:58Z","isPatch":false,"sender":{"key":"galtgendo@gmail.com","avatar":null},"body":"I just stumbled upon this while checking a few mailing lists.\nI haven't found any mails about in in the archives yet, so I assume, that\nno mail have been written yet.\n\nThe problem is described here:\nhttp://sourceforge.net/projects/sevenzip/forums/forum/45798/topic/5322604\n\nBasically, while this is not a problem for GNU tar, the correct checksum\nshould be computed using unsigned values.\n\nAttached trivial testcase shows the difference.\n\nPatch making the change shown in the testcase also attached.\n\n\n\n#include <stdio.h>\n#include <string.h>\n\nstatic unsigned int ustar_header_chksum(const void *buffer, int sign)\n{\n  const char *p = (const char *)buffer;\n  unsigned int chksum = 0;\n  while (p < (const char *)buffer + strlen(buffer))\n  {\n    if (sign) chksum += *p++; else chksum += (unsigned char)*p++;\n  }\n  return chksum;\n}\n\nint main(int argc, char** argv)\n{\nconst char* teststring = \"żółte źrebię\";\nprintf(\"%u\\n\", ustar_header_chksum(teststring, 0));\nprintf(\"%u\\n\", ustar_header_chksum(teststring, 1));\nreturn 0;\n}\n\n--- archive-tar.c\t2012-04-26 21:25:49.000000000 +0200\n+++ archive-tar.c\t2012-06-13 16:43:59.220945967 +0200\n@@ -104,11 +104,11 @@ static unsigned int ustar_header_chksum(\n \tchar *p = (char *)header;\n \tunsigned int chksum = 0;\n \twhile (p < header->chksum)\n-\t\tchksum += *p++;\n+\t\tchksum += (unsigned char)*p++;\n \tchksum += sizeof(header->chksum) * ' ';\n \tp += sizeof(header->chksum);\n \twhile (p < (char *)header + sizeof(struct ustar_header))\n-\t\tchksum += *p++;\n+\t\tchksum += (unsigned char)*p++;\n \treturn chksum;\n }\n \n"},{"id":"193558","messageId":"7vmx47gl6n.fsf@alter.siamese.dyndns.org","threadId":"30794","inReplyTo":"20120613144758.GA2438@blackspire","subject":"Re: A slight inconvenience with 'git archive --format=tar'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-13T17:45:36Z","receivedAt":"2012-06-13T17:45:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rafał Mużyło <galtgendo@gmail.com> writes:\n\n> I just stumbled upon this while checking a few mailing lists.\n> I haven't found any mails about in in the archives yet, so I assume, that\n> no mail have been written yet.\n>\n> The problem is described here:\n> http://sourceforge.net/projects/sevenzip/forums/forum/45798/topic/5322604\n\nThanks.  It sounds a bit more than \"slight inconvenience\" to me ;-)\n\n-- >8 --\nDate: Wed, 13 Jun 2012 10:42:25 -0700\nSubject: [PATCH] archive: ustar header checksum is computed unsigned\n\nPOSIX.1 (pax) is pretty clear on this:\n\n  The chksum field shall be the ISO/IEC 646:1991 standard IRV\n  representation of the octal value of the simple sum of all octets\n  in the header logical record. Each octet in the header shall be\n  treated as an unsigned value. These values shall be added to an\n  unsigned integer, initialized to zero, the precision of which is\n  not less than 17 bits. When calculating the checksum, the chksum\n  field is treated as if it were all <space> characters.\n\nso is GNU:\n\n  http://www.gnu.org/software/tar/manual/html_node/Checksumming.html\n\nFound by 7zip folks and reported by Rafał Mużyło.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n archive-tar.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/archive-tar.c b/archive-tar.c\nindex dc91c6b..0ba3f25 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -139,13 +139,13 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,\n \n static unsigned int ustar_header_chksum(const struct ustar_header *header)\n {\n-\tconst char *p = (const char *)header;\n+\tconst unsigned char *p = (const unsigned char *)header;\n \tunsigned int chksum = 0;\n-\twhile (p < header->chksum)\n+\twhile (p < (const unsigned char *)header->chksum)\n \t\tchksum += *p++;\n \tchksum += sizeof(header->chksum) * ' ';\n \tp += sizeof(header->chksum);\n-\twhile (p < (const char *)header + sizeof(struct ustar_header))\n+\twhile (p < (const unsigned char *)header + sizeof(struct ustar_header))\n \t\tchksum += *p++;\n \treturn chksum;\n }\n-- \n1.7.11.rc3.25.g4c2075b\n"},{"id":"193587","messageId":"4FD8F0E7.40706@lsrfire.ath.cx","threadId":"30794","inReplyTo":"7vmx47gl6n.fsf@alter.siamese.dyndns.org","subject":"Re: A slight inconvenience with 'git archive --format=tar'","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2012-06-13T19:58:31Z","receivedAt":"2012-06-13T19:58:31Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 13.06.2012 19:45, schrieb Junio C Hamano:\n> Rafał Mużyło <galtgendo@gmail.com> writes:\n>\n>> I just stumbled upon this while checking a few mailing lists.\n>> I haven't found any mails about in in the archives yet, so I assume, that\n>> no mail have been written yet.\n>>\n>> The problem is described here:\n>> http://sourceforge.net/projects/sevenzip/forums/forum/45798/topic/5322604\n>\n> Thanks.  It sounds a bit more than \"slight inconvenience\" to me ;-)\n\nIndeed, but two mitigating factors, if you will, are that this only \naffects files whose path or link target contain non-ASCII characters, \nand -- as Rafał wrote -- that GNU tar silently accepts signed checksums \nas well, which makes it a bit difficult to test.\n\nRené\n"}]}