git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] NUL terminate the object data in patch_delta()

From
Sergey Vlasov <vsu@altlinux.ru>
Date
Sep 4, 2005, 09:43 UTC
Message-ID
<20050904094316.GB11653@procyon.home>

At least pretty_print_commit() expects to get NUL-terminated commit data to work properly. unpack_sha1_rest(), which reads objects from separate files, and unpack_non_delta_entry(), which reads non-delta-compressed objects from pack files, already add the NUL byte after the object data, but patch_delta() did not do it, which caused problems with, e.g., git-rev-list --pretty when there are delta-compressed commit objects.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
---

Actually I noticed the problem when trying to do "git log ^v2.6.12 v2.6.13" on the linux-2.6 repository - the output was not identical to the original ChangeLog-2.6.13; some commits had garbage at the end of message.

Valgrind catches this problem with messages like:

==22513== 6 errors in context 6 of 7: ==22513== Invalid read of size 1 ==22513== at 0x804E148: pretty_print_commit (commit.c:382) ==22513== by 0x8049A00: process_commit (rev-list.c:73) ==22513== by 0x804A1E6: main (rev-list.c:168) ==22513== Address 0x1BF2EC23 is 8 bytes after a block of size 459 alloc'd ==22513== at 0x1B8FFAD8: malloc (vg_replace_malloc.c:130) ==22513== by 0x804F9B6: patch_delta (patch-delta.c:37) ==22513== by 0x804BFE7: unpack_entry_gently (sha1_file.c:941) ==22513== by 0x804C2FA: read_packed_sha1 (sha1_file.c:987) ==22513== by 0x804C378: read_sha1_file (sha1_file.c:1147) ==22513== by 0x804DD91: parse_commit (commit.c:257) ==22513== by 0x804DF1A: pop_most_recent_commit (commit.c:329) ==22513== by 0x804A07D: main (rev-list.c:378) ==22513== ==22513== 260 errors in context 7 of 7: ==22513== Invalid read of size 1 ==22513== at 0x804E050: pretty_print_commit (commit.c:347) ==22513== by 0x8049A00: process_commit (rev-list.c:73) ==22513== by 0x804A1E6: main (rev-list.c:168) ==22513== Address 0x1BC30C46 is 0 bytes after a block of size 430 alloc'd ==22513== at 0x1B8FFAD8: malloc (vg_replace_malloc.c:130) ==22513== by 0x804F9B6: patch_delta (patch-delta.c:37) ==22513== by 0x804BFE7: unpack_entry_gently (sha1_file.c:941) ==22513== by 0x804C2FA: read_packed_sha1 (sha1_file.c:987) ==22513== by 0x804C378: read_sha1_file (sha1_file.c:1147) ==22513== by 0x804DD91: parse_commit (commit.c:257) ==22513== by 0x804DF1A: pop_most_recent_commit (commit.c:329) ==22513== by 0x804A07D: main (rev-list.c:378)

 patch-delta.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
121db224f0f2595067e3bf7daed6c6a903d7532b
diff --git a/patch-delta.c b/patch-delta.c
--- a/patch-delta.c
+++ b/patch-delta.c
@@ -34,9 +34,10 @@ void *patch_delta(void *src_buf, unsigne
 
 	/* now the result size */
 	size = get_delta_hdr_size(&data);
-	dst_buf = malloc(size);
+	dst_buf = malloc(size + 1);
 	if (!dst_buf)
 		return NULL;
+	dst_buf[size] = 0;
 
 	out = dst_buf;
 	while (data < top) {
Message 1 of 1 in “NUL terminate the object data in patch_delta()”
  1. NUL terminate the object data in patch_delta()Sergey Vlasov, Sep 4, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.