summaryrefslogtreecommitdiff
path: root/chunk-format.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-02-18 14:07:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-02-18 21:38:16 (GMT)
commit5387fefadc121cb142e513557997415f2e75188a (patch)
tree787fd9e4f37248b07148c892791b45711a533360 /chunk-format.c
parent329fac3a366244ceac599ab63cd338bcc6a1dcb4 (diff)
downloadgit-5387fefadc121cb142e513557997415f2e75188a.zip
git-5387fefadc121cb142e513557997415f2e75188a.tar.gz
git-5387fefadc121cb142e513557997415f2e75188a.tar.bz2
chunk-format: restore duplicate chunk checks
Before refactoring into the chunk-format API, the commit-graph parsing logic included checks for duplicate chunks. It is unlikely that we would desire a chunk-based file format that allows duplicate chunk IDs in the table of contents, so add duplicate checks into read_table_of_contents(). Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'chunk-format.c')
-rw-r--r--chunk-format.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/chunk-format.c b/chunk-format.c
index 2c1fecf..da191e5 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -97,6 +97,7 @@ int read_table_of_contents(struct chunkfile *cf,
uint64_t toc_offset,
int toc_length)
{
+ int i;
uint32_t chunk_id;
const unsigned char *table_of_contents = mfile + toc_offset;
@@ -123,6 +124,14 @@ int read_table_of_contents(struct chunkfile *cf,
return -1;
}
+ for (i = 0; i < cf->chunks_nr; i++) {
+ if (cf->chunks[i].id == chunk_id) {
+ error(_("duplicate chunk ID %"PRIx32" found"),
+ chunk_id);
+ return -1;
+ }
+ }
+
cf->chunks[cf->chunks_nr].id = chunk_id;
cf->chunks[cf->chunks_nr].start = mfile + chunk_offset;
cf->chunks[cf->chunks_nr].size = next_chunk_offset - chunk_offset;