Skip to content

Commit 5387fef

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 329fac3 commit 5387fef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

chunk-format.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int read_table_of_contents(struct chunkfile *cf,
9797
uint64_t toc_offset,
9898
int toc_length)
9999
{
100+
int i;
100101
uint32_t chunk_id;
101102
const unsigned char *table_of_contents = mfile + toc_offset;
102103

@@ -123,6 +124,14 @@ int read_table_of_contents(struct chunkfile *cf,
123124
return -1;
124125
}
125126

127+
for (i = 0; i < cf->chunks_nr; i++) {
128+
if (cf->chunks[i].id == chunk_id) {
129+
error(_("duplicate chunk ID %"PRIx32" found"),
130+
chunk_id);
131+
return -1;
132+
}
133+
}
134+
126135
cf->chunks[cf->chunks_nr].id = chunk_id;
127136
cf->chunks[cf->chunks_nr].start = mfile + chunk_offset;
128137
cf->chunks[cf->chunks_nr].size = next_chunk_offset - chunk_offset;

0 commit comments

Comments
 (0)