]> Kevux Git Server - rit/commitdiff
packfile: avoid overflowing shift during decode
authorJonathan Tan <jonathantanmy@google.com>
Wed, 10 Nov 2021 23:40:33 +0000 (15:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Nov 2021 18:06:37 +0000 (10:06 -0800)
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 <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c

index 9ef6d98..d3820c7 100644 (file)
@@ -1067,7 +1067,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
        size = c & 15;
        shift = 4;
        while (c & 0x80) {
-               if (len <= used || bitsizeof(long) <= shift) {
+               if (len <= used || (bitsizeof(long) - 7) <= shift) {
                        error("bad object header");
                        size = used = 0;
                        break;