Skip to content

Commit

Permalink
chunk-format: restore duplicate chunk checks
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
derrickstolee authored and gitster committed Feb 18, 2021
1 parent 329fac3 commit 5387fef
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chunk-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 5387fef

Please sign in to comment.