mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
Merge pull request #7172 from Oblivionsage/main
delta: fix undefined behavior in hdr_sz varint parsing
This commit is contained in:
@@ -477,8 +477,12 @@ static int hdr_sz(
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (shift >= (sizeof(size_t) * 8)) {
|
||||
git_error_set(GIT_ERROR_INVALID, "delta header overflow");
|
||||
return -1;
|
||||
}
|
||||
c = *d++;
|
||||
r |= (c & 0x7f) << shift;
|
||||
r |= ((size_t)(c & 0x7f)) << shift;
|
||||
shift += 7;
|
||||
} while (c & 0x80);
|
||||
*delta = d;
|
||||
|
||||
16
tests/libgit2/delta/shift_overflow.c
Normal file
16
tests/libgit2/delta/shift_overflow.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "delta.h"
|
||||
|
||||
void test_delta_shift_overflow__hdr_sz_shift_limit(void)
|
||||
{
|
||||
unsigned char base[16] = { 0 };
|
||||
unsigned char delta[] = {
|
||||
0x80, 0x80, 0x80, 0x80, 0x80,
|
||||
0x80, 0x80, 0x80, 0x80,
|
||||
0x80, 0x01
|
||||
};
|
||||
void *out;
|
||||
size_t outlen;
|
||||
|
||||
cl_git_fail(git_delta_apply(&out, &outlen, base, sizeof(base), delta, sizeof(delta)));
|
||||
}
|
||||
Reference in New Issue
Block a user