commit: allocate array using object_id size

struct commit_graft aggregates an array of object_id's, which have size >= GIT_MAX_RAWSZ bytes. This change prevents memory allocation error when size of object_id is larger than GIT_SHA1_RAWSZ. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patryk Obara committed Aug 18, 2017 at 20:33 UTC bc65d2262d7c676cc7a0100d8be84a0690e10702
1 file changed +2 -1
commit.c
+2 -1
@@ -147,7 +147,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)
147 if ((line->len + 1) % entry_size)
148 goto bad_graft_data;
149 i = (line->len + 1) / entry_size - 1;
150 - graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
150 + graft = xmalloc(st_add(sizeof(*graft),
151 + st_mult(sizeof(struct object_id), i)));
152 graft->nr_parent = i;
153 if (get_oid_hex(line->buf, &graft->oid))
154 goto bad_graft_data;