Skip to content

Commit bc65d22

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a93403 commit bc65d22

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ struct commit_graft *read_graft_line(struct strbuf *line)
147147
if ((line->len + 1) % entry_size)
148148
goto bad_graft_data;
149149
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)));
151152
graft->nr_parent = i;
152153
if (get_oid_hex(line->buf, &graft->oid))
153154
goto bad_graft_data;

0 commit comments

Comments
 (0)