diff options
| author | Junio C Hamano <gitster@pobox.com> | 2021-07-16 17:42:46 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2021-07-16 17:42:46 -0700 |
| commit | 3b57e72c0c37b972240387cf7c4eb9d87f799c87 (patch) | |
| tree | 0e44b3c4ef9a3bf077d47a94c66e9b61a763c489 /commit-graph.c | |
| parent | Merge branch 'en/merge-dir-rename-corner-case-fix' (diff) | |
| parent | midx: report checksum mismatches during 'verify' (diff) | |
| download | git-3b57e72c0c37b972240387cf7c4eb9d87f799c87.tar.gz git-3b57e72c0c37b972240387cf7c4eb9d87f799c87.zip | |
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 'commit-graph.c')
| -rw-r--r-- | commit-graph.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/commit-graph.c b/commit-graph.c index 2bcb4e0f89..1a2602da61 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2422,14 +2422,16 @@ static void graph_report(const char *fmt, ...) #define GENERATION_ZERO_EXISTS 1 #define GENERATION_NUMBER_EXISTS 2 +static int commit_graph_checksum_valid(struct commit_graph *g) +{ + return hashfile_checksum_valid(g->data, g->data_len); +} + int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) { uint32_t i, cur_fanout_pos = 0; struct object_id prev_oid, cur_oid; - unsigned char checksum[GIT_MAX_HEXSZ]; int generation_zero = 0; - struct hashfile *f; - int devnull; struct progress *progress = NULL; int local_error = 0; @@ -2442,11 +2444,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) if (verify_commit_graph_error) return verify_commit_graph_error; - devnull = open("/dev/null", O_WRONLY); - f = hashfd(devnull, NULL); - hashwrite(f, g->data, g->data_len - g->hash_len); - finalize_hashfile(f, checksum, CSUM_CLOSE); - if (!hasheq(checksum, g->data + g->data_len - g->hash_len)) { + if (!commit_graph_checksum_valid(g)) { graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt")); verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH; } |
