Skip to content

Commit 06cafdf

Browse files
committed
pack: upcast to size_t for bounds checking
1 parent 6e8227a commit 06cafdf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/libgit2/pack.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ static int pack_entry_find_offset(
14991499
size_t len)
15001500
{
15011501
const uint32_t *level1_ofs;
1502+
size_t ofs_delta = 0;
15021503
const unsigned char *index;
15031504
unsigned hi, lo, stride;
15041505
int pos, found = 0;
@@ -1524,13 +1525,11 @@ static int pack_entry_find_offset(
15241525

15251526
if (p->index_version > 1) {
15261527
level1_ofs += 2;
1528+
ofs_delta = 2;
15271529
index += 8;
1530+
}
15281531

1529-
if ((int)short_oid->id[0] + 2 >= p->index_map.len) {
1530-
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->short_oid->[0] out of bounds");
1531-
goto cleanup;
1532-
}
1533-
} else if ((int)short_oid->id[0] >= p->index_map.len) {
1532+
if ((size_t)short_oid->id[0] + ofs_delta >= p->index_map.len) {
15341533
git_error_set(GIT_ERROR_INTERNAL, "internal error: p->short_oid->[0] out of bounds");
15351534
goto cleanup;
15361535
}

0 commit comments

Comments
 (0)