Skip to content

Commit 34de5b8

Browse files
jonathantanmygitster
authored andcommitted
packfile: avoid overflowing shift during decode
unpack_object_header_buffer() attempts to protect against overflowing left shifts, but the limit of the shift amount should not be the size of the variable being shifted. It should be the size minus the size of its contents. Fix that accordingly. This was noticed at $DAYJOB by a fuzzer running internally. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fbd2fc commit 34de5b8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
10671067
size = c & 15;
10681068
shift = 4;
10691069
while (c & 0x80) {
1070-
if (len <= used || bitsizeof(long) <= shift) {
1070+
if (len <= used || (bitsizeof(long) - 7) <= shift) {
10711071
error("bad object header");
10721072
size = used = 0;
10731073
break;

0 commit comments

Comments
 (0)