diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-01-16 12:07:47 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-01-16 12:07:47 -0800 |
| commit | ffd923868574a004ec20a80dbc3b813da9a93b08 (patch) | |
| tree | fb80c1309a6cd0528d7dcc77d20a18451ef278fc /read-cache.c | |
| parent | Merge branch 'ws/single-file-cone' (diff) | |
| parent | features: feature.manyFiles implies fast index writes (diff) | |
| download | git-ffd923868574a004ec20a80dbc3b813da9a93b08.tar.gz git-ffd923868574a004ec20a80dbc3b813da9a93b08.zip | |
Merge branch 'ds/omit-trailing-hash-in-index'
Introduce an optional configuration to allow the trailing hash that
protects the index file from bit flipping.
* ds/omit-trailing-hash-in-index:
features: feature.manyFiles implies fast index writes
test-lib-functions: add helper for trailing hash
read-cache: add index.skipHash config option
hashfile: allow skipping the hash function
Diffstat (limited to 'read-cache.c')
| -rw-r--r-- | read-cache.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/read-cache.c b/read-cache.c index 1ff518b2a7..cf87ad7097 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1817,6 +1817,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) git_hash_ctx c; unsigned char hash[GIT_MAX_RAWSZ]; int hdr_version; + unsigned char *start, *end; + struct object_id oid; if (hdr->hdr_signature != htonl(CACHE_SIGNATURE)) return error(_("bad signature 0x%08x"), hdr->hdr_signature); @@ -1827,10 +1829,16 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) if (!verify_index_checksum) return 0; + end = (unsigned char *)hdr + size; + start = end - the_hash_algo->rawsz; + oidread(&oid, start); + if (oideq(&oid, null_oid())) + return 0; + the_hash_algo->init_fn(&c); the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz); the_hash_algo->final_fn(hash, &c); - if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz)) + if (!hasheq(hash, start)) return error(_("bad index file sha1 signature")); return 0; } @@ -2920,9 +2928,13 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, int ieot_entries = 1; struct index_entry_offset_table *ieot = NULL; int nr, nr_threads; + struct repository *r = istate->repo ? istate->repo : the_repository; f = hashfd(tempfile->fd, tempfile->filename.buf); + prepare_repo_settings(r); + f->skip_hash = r->settings.index_skip_hash; + for (i = removed = extended = 0; i < entries; i++) { if (cache[i]->ce_flags & CE_REMOVE) removed++; |
