Skip to content

Commit a83e21d

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap.c: ensure pseudo-merge offset reads are bounded
After reading the pseudo-merge extension's metadata table, we allocate an array to store information about each pseudo-merge, including its byte offset within the .bitmap file itself. This is done like so: pseudo_merge_ofs = index_end - 24 - (index->pseudo_merges.nr * sizeof(uint64_t)); for (i = 0; i < index->pseudo_merges.nr; i++) { index->pseudo_merges.v[i].at = get_be64(pseudo_merge_ofs); pseudo_merge_ofs += sizeof(uint64_t); } But if the pseudo-merge table is corrupt, we'll keep calling get_be64() past the end of the pseudo-merge extension, potentially reading off the end of the mmap'd region. Prevent this by ensuring that we have at least `table_size - 24` many bytes available to read (adding 24 to the left-hand side of our inequality to account for the length of the metadata component). This is sufficient to prevent us from reading off the end of the pseudo-merge extension, and ensures that all of the get_be64() calls below are in bounds. Helped-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 20c4943 commit a83e21d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pack-bitmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ static int load_bitmap_header(struct bitmap_index *index)
238238
index->pseudo_merges.commits_nr = get_be32(index_end - 20);
239239
index->pseudo_merges.nr = get_be32(index_end - 24);
240240

241+
if (st_add(st_mult(index->pseudo_merges.nr,
242+
sizeof(uint64_t)),
243+
24) > table_size)
244+
return error(_("corrupted bitmap index file, pseudo-merge table too short"));
245+
241246
CALLOC_ARRAY(index->pseudo_merges.v,
242247
index->pseudo_merges.nr);
243248

0 commit comments

Comments
 (0)