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

Function read_table_of_contents

chunk-format.c:104–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104int read_table_of_contents(struct chunkfile *cf,
105 const unsigned char *mfile,
106 size_t mfile_size,
107 uint64_t toc_offset,
108 int toc_length,
109 unsigned expected_alignment)
110{
111 int i;
112 uint32_t chunk_id;
113 const unsigned char *table_of_contents = mfile + toc_offset;
114
115 ALLOC_GROW(cf->chunks, toc_length, cf->chunks_alloc);
116
117 while (toc_length--) {
118 uint64_t chunk_offset, next_chunk_offset;
119
120 chunk_id = get_be32(table_of_contents);
121 chunk_offset = get_be64(table_of_contents + 4);
122
123 if (!chunk_id) {
124 error(_("terminating chunk id appears earlier than expected"));
125 return 1;
126 }
127 if (chunk_offset % expected_alignment != 0) {
128 error(_("chunk id %"PRIx32" not %d-byte aligned"),
129 chunk_id, expected_alignment);
130 return 1;
131 }
132
133 table_of_contents += CHUNK_TOC_ENTRY_SIZE;
134 next_chunk_offset = get_be64(table_of_contents + 4);
135
136 if (next_chunk_offset < chunk_offset ||
137 next_chunk_offset > mfile_size - the_hash_algo->rawsz) {
138 error(_("improper chunk offset(s) %"PRIx64" and %"PRIx64""),
139 chunk_offset, next_chunk_offset);
140 return -1;
141 }
142
143 for (i = 0; i < cf->chunks_nr; i++) {
144 if (cf->chunks[i].id == chunk_id) {
145 error(_("duplicate chunk ID %"PRIx32" found"),
146 chunk_id);
147 return -1;
148 }
149 }
150
151 cf->chunks[cf->chunks_nr].id = chunk_id;
152 cf->chunks[cf->chunks_nr].start = mfile + chunk_offset;
153 cf->chunks[cf->chunks_nr].size = next_chunk_offset - chunk_offset;
154 cf->chunks_nr++;
155 }
156
157 chunk_id = get_be32(table_of_contents);
158 if (chunk_id) {
159 error(_("final chunk has non-zero id %"PRIx32""), chunk_id);
160 return -1;
161 }

Callers 2

parse_commit_graphFunction · 0.85

Calls 3

get_be32Function · 0.85
get_be64Function · 0.85
errorFunction · 0.85

Tested by

no test coverage detected