pack: upcast to size_t for bounds checking

This commit is contained in:
Edward Thomson
2024-04-19 09:58:47 +01:00
parent 6e8227ab38
commit 06cafdf9d8

View File

@@ -1499,6 +1499,7 @@ static int pack_entry_find_offset(
size_t len)
{
const uint32_t *level1_ofs;
size_t ofs_delta = 0;
const unsigned char *index;
unsigned hi, lo, stride;
int pos, found = 0;
@@ -1524,13 +1525,11 @@ static int pack_entry_find_offset(
if (p->index_version > 1) {
level1_ofs += 2;
ofs_delta = 2;
index += 8;
}
if ((int)short_oid->id[0] + 2 >= p->index_map.len) {
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->short_oid->[0] out of bounds");
goto cleanup;
}
} else if ((int)short_oid->id[0] >= p->index_map.len) {
if ((size_t)short_oid->id[0] + ofs_delta >= p->index_map.len) {
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->short_oid->[0] out of bounds");
goto cleanup;
}