Skip to content

Commit 30d9176

Browse files
authored
Merge pull request libgit2#4435 from lhchavez/ubsan-shift-overflow
libFuzzer: Prevent a potential shift overflow
2 parents 1ddc57b + 53f2c6b commit 30d9176

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/pack.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,19 +934,19 @@ git_off_t get_delta_base(
934934
if (type == GIT_OBJ_OFS_DELTA) {
935935
unsigned used = 0;
936936
unsigned char c = base_info[used++];
937-
base_offset = c & 127;
937+
size_t unsigned_base_offset = c & 127;
938938
while (c & 128) {
939939
if (left <= used)
940940
return GIT_EBUFS;
941-
base_offset += 1;
942-
if (!base_offset || MSB(base_offset, 7))
941+
unsigned_base_offset += 1;
942+
if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
943943
return 0; /* overflow */
944944
c = base_info[used++];
945-
base_offset = (base_offset << 7) + (c & 127);
945+
unsigned_base_offset = (unsigned_base_offset << 7) + (c & 127);
946946
}
947-
base_offset = delta_obj_offset - base_offset;
948-
if (base_offset <= 0 || base_offset >= delta_obj_offset)
947+
if (unsigned_base_offset == 0 || (size_t)delta_obj_offset <= unsigned_base_offset)
949948
return 0; /* out of bound */
949+
base_offset = delta_obj_offset - unsigned_base_offset;
950950
*curpos += used;
951951
} else if (type == GIT_OBJ_REF_DELTA) {
952952
/* If we have the cooperative cache, search in it first */

0 commit comments

Comments
 (0)