Skip to content

Commit 2bd0365

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9b9f8a commit 2bd0365

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

commit-graph.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,5 +848,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
848848
return 1;
849849
}
850850

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+
851860
return verify_commit_graph_error;
852861
}

t/t5318-commit-graph.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ test_expect_success 'git commit-graph verify' '
249249

250250
GRAPH_BYTE_VERSION=4
251251
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))
252261

253262
# usage: corrupt_graph_and_verify <position> <data> <string>
254263
# Manipulates the commit-graph file at the position
@@ -283,4 +292,24 @@ test_expect_success 'detect bad hash version' '
283292
"hash version"
284293
'
285294

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+
286315
test_done

0 commit comments

Comments
 (0)