path: root/delta.h
diff options
authorMatt Cooper <>2021-11-02 15:46:10 (GMT)
committerJunio C Hamano <>2021-11-03 18:22:27 (GMT)
commitd6a09e795d77ddc76c5141047340dc3cb62355f4 (patch)
tree37f068272f06f44d2b3ddfe77d700e74e8bc8772 /delta.h
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 <> Signed-off-by: Matt Cooper <> Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'delta.h')
1 files changed, 3 insertions, 3 deletions
diff --git a/delta.h b/delta.h
index 2df5fe1..8a56ec0 100644
--- a/delta.h
+++ b/delta.h
@@ -90,15 +90,15 @@ static inline unsigned long get_delta_hdr_size(const unsigned char **datap,
const unsigned char *top)
const unsigned char *data = *datap;
- unsigned long cmd, size = 0;
+ size_t cmd, size = 0;
int i = 0;
do {
cmd = *data++;
- size |= (cmd & 0x7f) << i;
+ size |= st_left_shift(cmd & 0x7f, i);
i += 7;
} while (cmd & 0x80 && data < top);
*datap = data;
- return size;
+ return cast_size_t_to_ulong(size);