{"thread":{"id":"66654","subject":"[PATCH] oss-fuzz: set a gitdir in the commit-graph fuzzer","startedAt":"2026-10-24T18:50:42Z","lastAt":"2026-10-29T12:23:53Z","messageCount":2,"participants":["Sami Jawhar","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"556186","messageId":"CAOJ8FdeyJp4ZOfp99DBSp4brWzngdqzrkSY36ByEh=4UPw28Mg@mail.gmail.com","threadId":"66654","inReplyTo":null,"subject":"[PATCH] oss-fuzz: set a gitdir in the commit-graph fuzzer","fromName":"Sami Jawhar","fromEmail":"sami@theorem.dev","sentAt":"2026-10-24T18:50:42Z","receivedAt":"2026-10-24T18:50:42Z","isPatch":true,"sender":{"key":"sami@theorem.dev","avatar":null},"body":"Since f1141b4391 (commit-graph: refactor `parse_commit_graph()` to take\na repository, 2025-08-15), parse_commit_graph() calls\nprepare_repo_settings().\n\nThe fuzzer sets settings.initialized, so that git reads no\nconfiguration. But prepare_repo_settings() checks for a gitdir before\nit reads that flag, and the repository of the fuzzer has no gitdir.\nThus each input that passes the header and the three required chunks\nstops at\n\n    BUG: repo-settings.c:40: Cannot add settings for uninitialized repository\n\nThe fuzzer never reaches the code that reads the optional chunks:\ngeneration data and changed-path Bloom filters.\n\nSet a placeholder gitdir, as test-path-utils does.\nprepare_repo_settings() checks only that the gitdir is not NULL. It\nthen returns, because the fuzzer marks the settings as initialized.\nrepo_clear() frees the gitdir, and no code opens a file under it.\n\nSigned-off-by: Sami Jawhar <sami@theorem.dev>\n---\n oss-fuzz/fuzz-commit-graph.c | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c\nindex 59bbb84..9a226eb 100644\n--- a/oss-fuzz/fuzz-commit-graph.c\n+++ b/oss-fuzz/fuzz-commit-graph.c\n@@ -20,6 +20,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)\n \t * possible.\n \t */\n \trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n+\tthe_repository->gitdir = xstrdup(\".git\");\n \tthe_repository->settings.initialized = 1;\n \tthe_repository->settings.commit_graph_generation_version = 2;\n \tthe_repository->settings.commit_graph_changed_paths_version = 1;\n\n"},{"id":"556772","messageId":"auM62Vqs56Gv5qjM@pks.im","threadId":"66654","inReplyTo":"CAOJ8FdeyJp4ZOfp99DBSp4brWzngdqzrkSY36ByEh=4UPw28Mg@mail.gmail.com","subject":"Re: [PATCH] oss-fuzz: set a gitdir in the commit-graph fuzzer","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-29T12:23:53Z","receivedAt":"2026-10-29T12:23:53Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sat, Oct 24, 2026 at 11:50:42AM -0700, Sami Jawhar wrote:\n> Since f1141b4391 (commit-graph: refactor `parse_commit_graph()` to take\n> a repository, 2025-08-15), parse_commit_graph() calls\n> prepare_repo_settings().\n> \n> The fuzzer sets settings.initialized, so that git reads no\n> configuration. But prepare_repo_settings() checks for a gitdir before\n> it reads that flag, and the repository of the fuzzer has no gitdir.\n> Thus each input that passes the header and the three required chunks\n> stops at\n> \n>     BUG: repo-settings.c:40: Cannot add settings for uninitialized repository\n> \n> The fuzzer never reaches the code that reads the optional chunks:\n> generation data and changed-path Bloom filters.\n\nOh, indeed. I thought that at one point in time we did a smoke test of\nour fuzzers that would have detected issues like this. But seemingly we\ndon't, or otherwise our CI would have failed.\n\nIt would be great to restore that so that fuzzers don't silently break\nanymore, but that's certainly outside the scope of this patch series.\n\n> diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c\n> index 59bbb84..9a226eb 100644\n> --- a/oss-fuzz/fuzz-commit-graph.c\n> +++ b/oss-fuzz/fuzz-commit-graph.c\n> @@ -20,6 +20,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)\n>  \t * possible.\n>  \t */\n>  \trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> +\tthe_repository->gitdir = xstrdup(\".git\");\n>  \tthe_repository->settings.initialized = 1;\n>  \tthe_repository->settings.commit_graph_generation_version = 2;\n>  \tthe_repository->settings.commit_graph_changed_paths_version = 1;\n\nWe already call `repo_clear()`, so we don't have to manually free this,\neither.\n\nSo this looks good to me, thanks for the fix!\n\nPatrick\n\n"}]}