From: Jonathan Tan Date: Wed, 10 Nov 2021 23:40:33 +0000 (-0800) Subject: packfile: avoid overflowing shift during decode X-Git-Tag: v2.35.0-rc0~113^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34de5b8eac2743497bc1785f661b4184adce21f3;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/packfile.c b/packfile.c index 9ef6d98292..d3820c780b 100644 --- a/packfile.c +++ b/packfile.c @@ -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;