MCPcopy Create free account
hub / github.com/git/git / verify_hdr

Function verify_hdr

read-cache.c:1701–1730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1699int verify_ce_order;
1700
1701static int verify_hdr(const struct cache_header *hdr, unsigned long size)
1702{
1703 struct git_hash_ctx c;
1704 unsigned char hash[GIT_MAX_RAWSZ];
1705 int hdr_version;
1706 unsigned char *start, *end;
1707 struct object_id oid;
1708
1709 if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
1710 return error(_("bad signature 0x%08x"), hdr->hdr_signature);
1711 hdr_version = ntohl(hdr->hdr_version);
1712 if (hdr_version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < hdr_version)
1713 return error(_("bad index version %d"), hdr_version);
1714
1715 if (!verify_index_checksum)
1716 return 0;
1717
1718 end = (unsigned char *)hdr + size;
1719 start = end - the_hash_algo->rawsz;
1720 oidread(&oid, start, the_repository->hash_algo);
1721 if (oideq(&oid, null_oid(the_hash_algo)))
1722 return 0;
1723
1724 the_hash_algo->init_fn(&c);
1725 git_hash_update(&c, hdr, size - the_hash_algo->rawsz);
1726 git_hash_final(hash, &c);
1727 if (!hasheq(hash, start, the_repository->hash_algo))
1728 return error(_("bad index file sha1 signature"));
1729 return 0;
1730}
1731
1732static int read_index_extension(struct index_state *istate,
1733 const char *ext, const char *data, unsigned long sz)

Callers 1

do_read_indexFunction · 0.85

Calls 7

errorFunction · 0.85
oidreadFunction · 0.85
oideqFunction · 0.85
null_oidFunction · 0.85
git_hash_updateFunction · 0.85
git_hash_finalFunction · 0.85
hasheqFunction · 0.85

Tested by

no test coverage detected