commit-graph: verify required chunks are present

The commit-graph file requires the following three chunks: * OID Fanout * OID Lookup * Commit Data If any of these are missing, then the 'verify' subcommand should report a failure. This includes the chunk IDs malformed or the chunk count is truncated. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jun 27, 2018 at 09:24 UTC 2bd0365f374558ca053412966b51fe01885ea3b5
2 files changed +38
commit-graph.c
+9
@@ -848,5 +848,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
848 return 1;
849 }
850
851 + verify_commit_graph_error = 0;
852 +
853 + if (!g->chunk_oid_fanout)
854 + graph_report("commit-graph is missing the OID Fanout chunk");
855 + if (!g->chunk_oid_lookup)
856 + graph_report("commit-graph is missing the OID Lookup chunk");
857 + if (!g->chunk_commit_data)
858 + graph_report("commit-graph is missing the Commit Data chunk");
859 +
860 return verify_commit_graph_error;
861 }
t/t5318-commit-graph.sh
+29
@@ -249,6 +249,15 @@ test_expect_success 'git commit-graph verify' '
249
250 GRAPH_BYTE_VERSION=4
251 GRAPH_BYTE_HASH=5
252 +GRAPH_BYTE_CHUNK_COUNT=6
253 +GRAPH_CHUNK_LOOKUP_OFFSET=8
254 +GRAPH_CHUNK_LOOKUP_WIDTH=12
255 +GRAPH_CHUNK_LOOKUP_ROWS=5
256 +GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
257 +GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
258 + 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
259 +GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
260 + 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
261
262 # usage: corrupt_graph_and_verify <position> <data> <string>
263 # Manipulates the commit-graph file at the position
@@ -283,4 +292,24 @@ test_expect_success 'detect bad hash version' '
292 "hash version"
293 '
294
295 +test_expect_success 'detect low chunk count' '
296 + corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
297 + "missing the .* chunk"
298 +'
299 +
300 +test_expect_success 'detect missing OID fanout chunk' '
301 + corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
302 + "missing the OID Fanout chunk"
303 +'
304 +
305 +test_expect_success 'detect missing OID lookup chunk' '
306 + corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
307 + "missing the OID Lookup chunk"
308 +'
309 +
310 +test_expect_success 'detect missing commit data chunk' '
311 + corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
312 + "missing the Commit Data chunk"
313 +'
314 +
315 test_done