Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Cooper <vtbassmatt@gmail.com>2021-11-02 18:46:10 +0300
committerJunio C Hamano <gitster@pobox.com>2021-11-03 21:22:27 +0300
commitd6a09e795d77ddc76c5141047340dc3cb62355f4 (patch)
tree37f068272f06f44d2b3ddfe77d700e74e8bc8772 /packfile.c
parente2ffeae3f6795939e1af9f8e2b5fa151343eec66 (diff)
odb: guard against data loss checking out a huge file
This introduces an additional guard for platforms where `unsigned long` and `size_t` are not of the same size. If the size of an object in the database would overflow `unsigned long`, instead we now exit with an error. A complete fix will have to update _many_ other functions throughout the codebase to use `size_t` instead of `unsigned long`. It will have to be implemented at some stage. This commit puts in a stop-gap for the time being. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Matt Cooper <vtbassmatt@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/packfile.c b/packfile.c
index 755aa7aec5..3ccea00439 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1059,7 +1059,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
unsigned long len, enum object_type *type, unsigned long *sizep)
{
unsigned shift;
- unsigned long size, c;
+ size_t size, c;
unsigned long used = 0;
c = buf[used++];
@@ -1073,10 +1073,10 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
break;
}
c = buf[used++];
- size += (c & 0x7f) << shift;
+ size = st_add(size, st_left_shift(c & 0x7f, shift));
shift += 7;
}
- *sizep = size;
+ *sizep = cast_size_t_to_ulong(size);
return used;
}