Skip to content

Commit 57165db

Browse files
peffgitster
authored andcommitted
index-pack: always zero-initialize object_entry list
Commit 38a4556 (index-pack: start learning to emulate "verify-pack -v", 2011-06-03) added a "delta_depth" counter to each "struct object_entry". Initially, all object entries have their depth set to 0; in resolve_delta, we then set the depth of each delta to "base + 1". Base entries never have their depth touched, and remain at 0. To ensure that all depths start at 0, that commit changed calls to xmalloc the object_entry list into calls to xcalloc. However, it forgot that we grow the list with xrealloc later. These extra entries are used when we add an object from elsewhere to complete a thin pack. If we add a non-delta object, its depth value will just be uninitialized heap data. This patch fixes it by zero-initializing entries we add to the objects list via the xrealloc. Signed-off-by: Jeff King <[email protected]> Acked-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e20105 commit 57165db

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,8 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
11061106
objects = xrealloc(objects,
11071107
(nr_objects + nr_unresolved + 1)
11081108
* sizeof(*objects));
1109+
memset(objects + nr_objects + 1, 0,
1110+
nr_unresolved * sizeof(*objects));
11091111
f = sha1fd(output_fd, curr_pack);
11101112
fix_unresolved_deltas(f, nr_unresolved);
11111113
sprintf(msg, "completed with %d local objects",

0 commit comments

Comments
 (0)