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:
authorTaylor Blau <me@ttaylorr.com>2021-06-23 21:39:07 +0300
committerJunio C Hamano <gitster@pobox.com>2021-06-29 06:36:17 +0300
commitf9221e2cf5049805d9151b3db6a5eef07b1cc92e (patch)
tree962e5c2742ae80de7f45353ba5813580caeeaa99 /pack-check.c
parentebf3c04b262aa27fbb97f8a0156c2347fecafafb (diff)
csum-file: introduce checksum_valid()
Introduce a new function which checks the validity of a file's trailing checksum. This is similar to hashfd_check(), but different since it is intended to be used by callers who aren't writing the same data (like `git index-pack --verify`), but who instead want to validate the integrity of data that they are reading. Rewrite the first of two callers which could benefit from this new function in pack-check.c. Subsequent callers will be added in the following patches. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-check.c')
-rw-r--r--pack-check.c11
1 files changed, 1 insertions, 10 deletions
diff --git a/pack-check.c b/pack-check.c
index 4b089fe8ec..c8e560d71a 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -164,22 +164,13 @@ static int verify_packfile(struct repository *r,
int verify_pack_index(struct packed_git *p)
{
- size_t len;
- const unsigned char *index_base;
- git_hash_ctx ctx;
- unsigned char hash[GIT_MAX_RAWSZ];
int err = 0;
if (open_pack_index(p))
return error("packfile %s index not opened", p->pack_name);
- index_base = p->index_data;
- len = p->index_size - the_hash_algo->rawsz;
/* Verify SHA1 sum of the index file */
- the_hash_algo->init_fn(&ctx);
- the_hash_algo->update_fn(&ctx, index_base, len);
- the_hash_algo->final_fn(hash, &ctx);
- if (!hasheq(hash, index_base + len))
+ if (!hashfile_checksum_valid(p->index_data, p->index_size))
err = error("Packfile index for %s hash mismatch",
p->pack_name);
return err;