diff mbox series

[6/6] commit-graph: test verifying a corrupt v2 header

Message ID 693900b4c5af9adb98d98549b9340ad9f9d09562.1548280754.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Create commit-graph file format v2 | expand

Commit Message

Derrick Stolee via GitGitGadget Jan. 23, 2019, 9:59 p.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

The commit-graph file format v2 changes the v1 data only in the
header information. Add tests that check the 'verify' subcommand
catches corruption in the v2 header.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 t/t5318-commit-graph.sh | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Jonathan Tan Jan. 23, 2019, 11:59 p.m. UTC | #1
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> The commit-graph file format v2 changes the v1 data only in the
> header information. Add tests that check the 'verify' subcommand
> catches corruption in the v2 header.

Ah, I should have read this patch before I wrote [1]. I think the commit
message of that patch should contain a note that verification of the v2
file format is done in a subsequent patch.

With or without that additional note, this series looks good to me.

[1] https://public-inbox.org/git/20190123235630.183779-1-jonathantanmy@google.com/

> 
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  t/t5318-commit-graph.sh | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
> index 3ff5e3b48d..be7bbf911a 100755
> --- a/t/t5318-commit-graph.sh
> +++ b/t/t5318-commit-graph.sh
> @@ -497,6 +497,37 @@ test_expect_success 'git fsck (checks commit-graph)' '
>  	test_must_fail git fsck
>  '
>  
> +test_expect_success 'rewrite commmit-graph with version 2' '
> +	rm -f .git/objects/info/commit-graph &&
> +	git commit-graph write --reachable --version=2 &&
> +	git commit-graph verify
> +'
> +
> +GRAPH_BYTE_CHUNK_COUNT=5
> +GRAPH_BYTE_REACH_INDEX=6
> +GRAPH_BYTE_UNUSED=7
> +GRAPH_BYTE_HASH=8
> +
> +test_expect_success 'detect low chunk count (v2)' '
> +	corrupt_graph_and_verify $GRAPH_CHUNK_COUNT "\02" \
> +		"missing the .* chunk"
> +'
> +
> +test_expect_success 'detect incorrect reachability index' '
> +	corrupt_graph_and_verify $GRAPH_REACH_INDEX "\03" \
> +		"reachability index version"
> +'
> +
> +test_expect_success 'detect non-zero unused byte' '
> +	corrupt_graph_and_verify $GRAPH_BYTE_UNUSED "\01" \
> +		"unsupported value"
> +'
> +
> +test_expect_success 'detect bad hash version (v2)' '
> +	corrupt_graph_and_verify $GRAPH_BYTE_HASH "\00" \
> +		"hash algorithm"
> +'
> +
>  test_expect_success 'setup non-the_repository tests' '
>  	rm -rf repo &&
>  	git init repo &&
> -- 
> gitgitgadget
diff mbox series

Patch

diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index 3ff5e3b48d..be7bbf911a 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -497,6 +497,37 @@  test_expect_success 'git fsck (checks commit-graph)' '
 	test_must_fail git fsck
 '
 
+test_expect_success 'rewrite commmit-graph with version 2' '
+	rm -f .git/objects/info/commit-graph &&
+	git commit-graph write --reachable --version=2 &&
+	git commit-graph verify
+'
+
+GRAPH_BYTE_CHUNK_COUNT=5
+GRAPH_BYTE_REACH_INDEX=6
+GRAPH_BYTE_UNUSED=7
+GRAPH_BYTE_HASH=8
+
+test_expect_success 'detect low chunk count (v2)' '
+	corrupt_graph_and_verify $GRAPH_CHUNK_COUNT "\02" \
+		"missing the .* chunk"
+'
+
+test_expect_success 'detect incorrect reachability index' '
+	corrupt_graph_and_verify $GRAPH_REACH_INDEX "\03" \
+		"reachability index version"
+'
+
+test_expect_success 'detect non-zero unused byte' '
+	corrupt_graph_and_verify $GRAPH_BYTE_UNUSED "\01" \
+		"unsupported value"
+'
+
+test_expect_success 'detect bad hash version (v2)' '
+	corrupt_graph_and_verify $GRAPH_BYTE_HASH "\00" \
+		"hash algorithm"
+'
+
 test_expect_success 'setup non-the_repository tests' '
 	rm -rf repo &&
 	git init repo &&