{"thread":{"id":"62316","subject":"[PATCH 0/2] t/helper/test-tool: implement 'sha1-unsafe' helper","startedAt":"2024-10-11T18:37:35Z","lastAt":"2024-10-11T18:37:41Z","messageCount":3,"participants":["Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"504870","messageId":"cover.1728671826.git.me@ttaylorr.com","threadId":"62316","inReplyTo":null,"subject":"[PATCH 0/2] t/helper/test-tool: implement 'sha1-unsafe' helper","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-11T18:37:29Z","receivedAt":"2024-10-11T18:37:35Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"This series implements a new 'sha1-unsafe' test helper, similar to\n't/helper/test-tool sha1'.\n\nI have found such a helper to be really handy when debugging the new\nSHA1_UNSAFE build knobs, e.g., to easily compare the performance of the\nsafe versus unsafe routines, different unsafe variants, etc.\n\nTaylor Blau (2):\n  t/helper/test-sha1: prepare for an unsafe mode\n  t/helper/test-tool: implement sha1-unsafe helper\n\n t/helper/test-hash.c   | 17 +++++++++++++----\n t/helper/test-sha1.c   |  7 ++++++-\n t/helper/test-sha1.sh  | 38 ++++++++++++++++++++++----------------\n t/helper/test-sha256.c |  2 +-\n t/helper/test-tool.c   |  1 +\n t/helper/test-tool.h   |  3 ++-\n 6 files changed, 45 insertions(+), 23 deletions(-)\n\n\nbase-commit: 777489f9e09c8d0dd6b12f9d90de6376330577a2\n-- \n2.47.0.2.gd343f5dc9e5\n"},{"id":"504871","messageId":"3b31db4d2df4889029422f48f65173e957c9e7e3.1728671826.git.me@ttaylorr.com","threadId":"62316","inReplyTo":"cover.1728671826.git.me@ttaylorr.com","subject":"[PATCH 1/2] t/helper/test-sha1: prepare for an unsafe mode","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-11T18:37:36Z","receivedAt":"2024-10-11T18:37:38Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"With the new \"unsafe\" SHA-1 build knob, it would be convenient to have\na test-tool that can exercise Git's unsafe SHA-1 wrappers for testing,\nsimilar to 't/helper/test-tool sha1'.\n\nPrepare for such a helper by altering the implementation of that\ntest-tool (in cmd_hash_impl(), which is generic and parameterized over\ndifferent hash functions) to conditionally run the unsafe variants of\nthe chosen hash function.\n\nThe following commit will add a new test-tool which makes use of this\nnew parameter.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n t/helper/test-hash.c   | 17 +++++++++++++----\n t/helper/test-sha1.c   |  2 +-\n t/helper/test-sha256.c |  2 +-\n t/helper/test-tool.h   |  2 +-\n 4 files changed, 16 insertions(+), 7 deletions(-)\n\ndiff --git a/t/helper/test-hash.c b/t/helper/test-hash.c\nindex 45d829c908f..d0ee668df95 100644\n--- a/t/helper/test-hash.c\n+++ b/t/helper/test-hash.c\n@@ -1,7 +1,7 @@\n #include \"test-tool.h\"\n #include \"hex.h\"\n \n-int cmd_hash_impl(int ac, const char **av, int algo)\n+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)\n {\n \tgit_hash_ctx ctx;\n \tunsigned char hash[GIT_MAX_HEXSZ];\n@@ -27,7 +27,10 @@ int cmd_hash_impl(int ac, const char **av, int algo)\n \t\t\tdie(\"OOPS\");\n \t}\n \n-\talgop->init_fn(&ctx);\n+\tif (unsafe)\n+\t\talgop->unsafe_init_fn(&ctx);\n+\telse\n+\t\talgop->init_fn(&ctx);\n \n \twhile (1) {\n \t\tssize_t sz, this_sz;\n@@ -46,9 +49,15 @@ int cmd_hash_impl(int ac, const char **av, int algo)\n \t\t}\n \t\tif (this_sz == 0)\n \t\t\tbreak;\n-\t\talgop->update_fn(&ctx, buffer, this_sz);\n+\t\tif (unsafe)\n+\t\t\talgop->unsafe_update_fn(&ctx, buffer, this_sz);\n+\t\telse\n+\t\t\talgop->update_fn(&ctx, buffer, this_sz);\n \t}\n-\talgop->final_fn(hash, &ctx);\n+\tif (unsafe)\n+\t\talgop->unsafe_final_fn(hash, &ctx);\n+\telse\n+\t\talgop->final_fn(hash, &ctx);\n \n \tif (binary)\n \t\tfwrite(hash, 1, algop->rawsz, stdout);\ndiff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c\nindex e60d000c039..1c1272cc1f9 100644\n--- a/t/helper/test-sha1.c\n+++ b/t/helper/test-sha1.c\n@@ -3,7 +3,7 @@\n \n int cmd__sha1(int ac, const char **av)\n {\n-\treturn cmd_hash_impl(ac, av, GIT_HASH_SHA1);\n+\treturn cmd_hash_impl(ac, av, GIT_HASH_SHA1, 0);\n }\n \n int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)\ndiff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c\nindex 2fb20438f3c..7fd0aa1fcd3 100644\n--- a/t/helper/test-sha256.c\n+++ b/t/helper/test-sha256.c\n@@ -3,5 +3,5 @@\n \n int cmd__sha256(int ac, const char **av)\n {\n-\treturn cmd_hash_impl(ac, av, GIT_HASH_SHA256);\n+\treturn cmd_hash_impl(ac, av, GIT_HASH_SHA256, 0);\n }\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex 21802ac27da..f3524d9a0f6 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -81,6 +81,6 @@ int cmd__windows_named_pipe(int argc, const char **argv);\n #endif\n int cmd__write_cache(int argc, const char **argv);\n \n-int cmd_hash_impl(int ac, const char **av, int algo);\n+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe);\n \n #endif\n-- \n2.47.0.2.gd343f5dc9e5\n\n"},{"id":"504872","messageId":"d343f5dc9e5614ccd5a0e92bbdd2d1fd3057dff6.1728671826.git.me@ttaylorr.com","threadId":"62316","inReplyTo":"cover.1728671826.git.me@ttaylorr.com","subject":"[PATCH 2/2] t/helper/test-tool: implement sha1-unsafe helper","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-11T18:37:39Z","receivedAt":"2024-10-11T18:37:41Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Add a new helper similar to 't/helper/test-tool sha1' called instead\n\"sha1-unsafe\" which uses the unsafe variant of Git's SHA-1 wrappers.\n\nWhile we're at it, modify the test-sha1.sh script to exercise both\nthe sha1 and sha1-unsafe test tools to ensure that both produce the\nexpected hash values.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n t/helper/test-sha1.c  |  5 +++++\n t/helper/test-sha1.sh | 38 ++++++++++++++++++++++----------------\n t/helper/test-tool.c  |  1 +\n t/helper/test-tool.h  |  1 +\n 4 files changed, 29 insertions(+), 16 deletions(-)\n\ndiff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c\nindex 1c1272cc1f9..349540c4df8 100644\n--- a/t/helper/test-sha1.c\n+++ b/t/helper/test-sha1.c\n@@ -13,3 +13,8 @@ int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)\n #endif\n \treturn 1;\n }\n+\n+int cmd__sha1_unsafe(int ac, const char **av)\n+{\n+\treturn cmd_hash_impl(ac, av, GIT_HASH_SHA1, 1);\n+}\ndiff --git a/t/helper/test-sha1.sh b/t/helper/test-sha1.sh\nindex 84594885c70..bf387d3db14 100755\n--- a/t/helper/test-sha1.sh\n+++ b/t/helper/test-sha1.sh\n@@ -3,25 +3,31 @@\n dd if=/dev/zero bs=1048576 count=100 2>/dev/null |\n /usr/bin/time t/helper/test-tool sha1 >/dev/null\n \n+dd if=/dev/zero bs=1048576 count=100 2>/dev/null |\n+/usr/bin/time t/helper/test-tool sha1-unsafe >/dev/null\n+\n while read expect cnt pfx\n do\n \tcase \"$expect\" in '#'*) continue ;; esac\n-\tactual=$(\n-\t\t{\n-\t\t\ttest -z \"$pfx\" || echo \"$pfx\"\n-\t\t\tdd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |\n-\t\t\tperl -pe 'y/\\000/g/'\n-\t\t} | ./t/helper/test-tool sha1 $cnt\n-\t)\n-\tif test \"$expect\" = \"$actual\"\n-\tthen\n-\t\techo \"OK: $expect $cnt $pfx\"\n-\telse\n-\t\techo >&2 \"OOPS: $cnt\"\n-\t\techo >&2 \"expect: $expect\"\n-\t\techo >&2 \"actual: $actual\"\n-\t\texit 1\n-\tfi\n+\tfor sha1 in sha1 sha1-unsafe\n+\tdo\n+\t\tactual=$(\n+\t\t\t{\n+\t\t\t\ttest -z \"$pfx\" || echo \"$pfx\"\n+\t\t\t\tdd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |\n+\t\t\t\tperl -pe 'y/\\000/g/'\n+\t\t\t} | ./t/helper/test-tool $sha1 $cnt\n+\t\t)\n+\t\tif test \"$expect\" = \"$actual\"\n+\t\tthen\n+\t\t\techo \"OK ($sha1): $expect $cnt $pfx\"\n+\t\telse\n+\t\t\techo >&2 \"OOPS ($sha1): $cnt\"\n+\t\t\techo >&2 \"expect ($sha1): $expect\"\n+\t\t\techo >&2 \"actual ($sha1): $actual\"\n+\t\t\texit 1\n+\t\tfi\n+\tdone\n done <<EOF\n da39a3ee5e6b4b0d3255bfef95601890afd80709 0\n 3f786850e387550fdab836ed7e6dc881de23001b 0 a\ndiff --git a/t/helper/test-tool.c b/t/helper/test-tool.c\nindex 1ebb69a5dc4..51ed25c07e2 100644\n--- a/t/helper/test-tool.c\n+++ b/t/helper/test-tool.c\n@@ -70,6 +70,7 @@ static struct test_cmd cmds[] = {\n \t{ \"serve-v2\", cmd__serve_v2 },\n \t{ \"sha1\", cmd__sha1 },\n \t{ \"sha1-is-sha1dc\", cmd__sha1_is_sha1dc },\n+\t{ \"sha1-unsafe\", cmd__sha1_unsafe },\n \t{ \"sha256\", cmd__sha256 },\n \t{ \"sigchain\", cmd__sigchain },\n \t{ \"simple-ipc\", cmd__simple_ipc },\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex f3524d9a0f6..24149edd414 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -63,6 +63,7 @@ int cmd__scrap_cache_tree(int argc, const char **argv);\n int cmd__serve_v2(int argc, const char **argv);\n int cmd__sha1(int argc, const char **argv);\n int cmd__sha1_is_sha1dc(int argc, const char **argv);\n+int cmd__sha1_unsafe(int argc, const char **argv);\n int cmd__sha256(int argc, const char **argv);\n int cmd__sigchain(int argc, const char **argv);\n int cmd__simple_ipc(int argc, const char **argv);\n-- \n2.47.0.2.gd343f5dc9e5\n"}]}