{"thread":{"id":"1722","subject":"[PATCH] NUL terminate the object data in patch_delta()","startedAt":"2005-09-04T09:43:16Z","lastAt":"2005-09-04T09:43:16Z","messageCount":1,"participants":["Sergey Vlasov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"8048","messageId":"20050904094316.GB11653@procyon.home","threadId":"1722","inReplyTo":null,"subject":"[PATCH] NUL terminate the object data in patch_delta()","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-09-04T09:43:16Z","receivedAt":"2005-09-04T09:43:16Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"At least pretty_print_commit() expects to get NUL-terminated commit data to\nwork properly.  unpack_sha1_rest(), which reads objects from separate files,\nand unpack_non_delta_entry(), which reads non-delta-compressed objects from\npack files, already add the NUL byte after the object data, but patch_delta()\ndid not do it, which caused problems with, e.g., git-rev-list --pretty when\nthere are delta-compressed commit objects.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n\n\n---\n\nActually I noticed the problem when trying to do \"git log ^v2.6.12\nv2.6.13\" on the linux-2.6 repository - the output was not identical to\nthe original ChangeLog-2.6.13; some commits had garbage at the end of\nmessage.\n\nValgrind catches this problem with messages like:\n\n==22513== 6 errors in context 6 of 7:\n==22513== Invalid read of size 1\n==22513==    at 0x804E148: pretty_print_commit (commit.c:382)\n==22513==    by 0x8049A00: process_commit (rev-list.c:73)\n==22513==    by 0x804A1E6: main (rev-list.c:168)\n==22513==  Address 0x1BF2EC23 is 8 bytes after a block of size 459 alloc'd\n==22513==    at 0x1B8FFAD8: malloc (vg_replace_malloc.c:130)\n==22513==    by 0x804F9B6: patch_delta (patch-delta.c:37)\n==22513==    by 0x804BFE7: unpack_entry_gently (sha1_file.c:941)\n==22513==    by 0x804C2FA: read_packed_sha1 (sha1_file.c:987)\n==22513==    by 0x804C378: read_sha1_file (sha1_file.c:1147)\n==22513==    by 0x804DD91: parse_commit (commit.c:257)\n==22513==    by 0x804DF1A: pop_most_recent_commit (commit.c:329)\n==22513==    by 0x804A07D: main (rev-list.c:378)\n==22513== \n==22513== 260 errors in context 7 of 7:\n==22513== Invalid read of size 1\n==22513==    at 0x804E050: pretty_print_commit (commit.c:347)\n==22513==    by 0x8049A00: process_commit (rev-list.c:73)\n==22513==    by 0x804A1E6: main (rev-list.c:168)\n==22513==  Address 0x1BC30C46 is 0 bytes after a block of size 430 alloc'd\n==22513==    at 0x1B8FFAD8: malloc (vg_replace_malloc.c:130)\n==22513==    by 0x804F9B6: patch_delta (patch-delta.c:37)\n==22513==    by 0x804BFE7: unpack_entry_gently (sha1_file.c:941)\n==22513==    by 0x804C2FA: read_packed_sha1 (sha1_file.c:987)\n==22513==    by 0x804C378: read_sha1_file (sha1_file.c:1147)\n==22513==    by 0x804DD91: parse_commit (commit.c:257)\n==22513==    by 0x804DF1A: pop_most_recent_commit (commit.c:329)\n==22513==    by 0x804A07D: main (rev-list.c:378)\n\n\n patch-delta.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\n121db224f0f2595067e3bf7daed6c6a903d7532b\ndiff --git a/patch-delta.c b/patch-delta.c\n--- a/patch-delta.c\n+++ b/patch-delta.c\n@@ -34,9 +34,10 @@ void *patch_delta(void *src_buf, unsigne\n \n \t/* now the result size */\n \tsize = get_delta_hdr_size(&data);\n-\tdst_buf = malloc(size);\n+\tdst_buf = malloc(size + 1);\n \tif (!dst_buf)\n \t\treturn NULL;\n+\tdst_buf[size] = 0;\n \n \tout = dst_buf;\n \twhile (data < top) {\n"}]}