git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] NUL terminate the object data in patch_delta()
@ 2005-09-04  9:43 Sergey Vlasov
  0 siblings, 0 replies; only message in thread
From: Sergey Vlasov @ 2005-09-04  9:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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) {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-09-04  9:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-04  9:43 [PATCH] NUL terminate the object data in patch_delta() Sergey Vlasov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).