summaryrefslogtreecommitdiff
path: root/csum-file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-07-17 00:42:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-17 00:42:46 (GMT)
commit3b57e72c0c37b972240387cf7c4eb9d87f799c87 (patch)
tree0e44b3c4ef9a3bf077d47a94c66e9b61a763c489 /csum-file.c
parentd3b88be1b450caa1244ed756c2fd7d7baadeafd8 (diff)
parentf89ecf79888a48e0adf14d0e05c69ee09e853fd5 (diff)
downloadgit-3b57e72c0c37b972240387cf7c4eb9d87f799c87.zip
git-3b57e72c0c37b972240387cf7c4eb9d87f799c87.tar.gz
git-3b57e72c0c37b972240387cf7c4eb9d87f799c87.tar.bz2
Merge branch 'tb/midx-use-checksum'
When rebuilding the multi-pack index file reusing an existing one, we used to blindly trust the existing file and ended up carrying corrupted data into the updated file, which has been corrected. * tb/midx-use-checksum: midx: report checksum mismatches during 'verify' midx: don't reuse corrupt MIDXs when writing commit-graph: rewrite to use checksum_valid() csum-file: introduce checksum_valid()
Diffstat (limited to 'csum-file.c')
-rw-r--r--csum-file.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/csum-file.c b/csum-file.c
index 3487d28..c951cf8 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -217,3 +217,19 @@ uint32_t crc32_end(struct hashfile *f)
f->do_crc = 0;
return f->crc32;
}
+
+int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
+{
+ unsigned char got[GIT_MAX_RAWSZ];
+ git_hash_ctx ctx;
+ size_t data_len = total_len - the_hash_algo->rawsz;
+
+ if (total_len < the_hash_algo->rawsz)
+ return 0; /* say "too short"? */
+
+ the_hash_algo->init_fn(&ctx);
+ the_hash_algo->update_fn(&ctx, data, data_len);
+ the_hash_algo->final_fn(got, &ctx);
+
+ return hasheq(got, data + data_len);
+}