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
This commit is contained in:
14
read-cache.c
14
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++;
|
||||
|
||||
Reference in New Issue
Block a user