From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796289227; b=lg3oZKUU5aHrSA5fSu0kC77l3dxZ+K4zm+SMJDQFtRVGG30cMdBMVq8Zj9nqqVRdKH6G w2sDs9jkhg4BTK2VXsDApCHqyhNhRwiDxqBiMQiKfl9BS4ynm38fLK9ZqyMAnYbEzvGy7 +QHcf3ZxABAnZTNr9Q4EddMlTcnzeG032dnqh3z83VvGVWApuajv32hd24wgtU+t81wOu oG7udgPKY6S7BiVpa8ItAjGqxjcE6YiCXEDR9Pj8YZfscmd3jGbdktke/ammcxdLozk1w rAP3ryOfIc6NPo3iaVBTUQdFqx3eZBUARTA4jV9Mrh80o/d5wK+3hrWaGDlo1LmD44A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289227; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=; b=j2kKMvc2i4k2hfRD+zVC0MiuL9QBK5Cv9rIgkIyfK0E40LtjcJIxcQJ+fzrsqb0FI6o6 d7dQ0GxnOUeFOFmqWiFwSl+OjtiiyGoM5xApWGl4HhTTTn8iv6gtwaRZGMvZAxTv+sDiR oTu47BzR/VUKNiD6AUCenvz+HmPRLasuAOuO0jCZq3lSJtvMmX/V+71XkCEQ7JY7xbVP7 A4Y09lRFcCKY+oMxc3JP4zNeF462XewxQOHavfMl47MHcyiHJNCk1my0Lmek4fgJhq4LM Dc7SnUe7/g6BH9b95A98t8MuYqCdtbSp+VNuBMjyjlYjVq43vZFUSZowuJk92vd/THA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=02vLTN8X; arc=none smtp.remote-ip=209.85.210.181 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 866B9606A33E for ; Thu, 3 Dec 2026 09:13:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 866B9606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=02vLTN8X Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8b67f25e6e1so7023825b3a.0 for ; Thu, 03 Dec 2026 01:13:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796289226; x=1796894026; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=; b=02vLTN8XXCSXYLXOjgCaZf40FfEeNPz2mPVp7UPfC/5FXgDjsRzEVGFg57iRW9on29 yNu4/V37dshVIcu58rJa+oSXI1JwVSI0y7HxEetrSzwU4IcQrujHLI1WqgqOu4WYthe0 Xj1PL67f8x9krPM0A5kM2zJNs2cJFBFCFQ0tUWlNW6L//WiFQwhEaJ5p1FlKcdq77BYg 6ItNpRpp+FN/FZqx1MvbLt2+k8vViVrGPywzJ58Gol+PbkzgYUBMG3kZRIxioPfRPblp 3qJj91Htoido+BCiI+AQ4zo6Ft8p1SSHkhoiwPadgyJvxFCYu+YYrzuE+mym85YL6aX1 OxSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796289226; x=1796894026; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ORlF1bSPaMxJOJiShRMtrcxmW5eb3mR+mU1UzDZC8Xg=; b=xegB1YwdCOeEjLJT47UXrC+gHlC6+fpO1uPA9S25TbfpIzuFzzXY1GAdCrkUCCTVHB d229+F9GNPTou6PnCWcVSFga/bm2XN/CbC7CNzl7y/yCs8hsHCJbv3Js0kMe4Wxfpk2c MPL7499f9n0FVoMW5rRqkF5V9hiYVXwCm9ZjN0b7ZzT18UrgnvYID61TIfpor0BZZ2aU uCemeLkURauzs4nkWtP9mfrbKkujZgcPtw+o60iOZtFsi+RZFZ9FMARKU+SMq4Ftm3PJ qSP0UmNfzXJeH5pI84B90pMDAkqHZm0BVQTNCTGRzxRBMl4pA8MXunkOAdt72NkHY9U2 W9sw== X-Forwarded-Encrypted: i=1; AL+hErFnrImyMtywtcUSPy1dKkLPmrYoPqnfDZmDq267kqOJw14kr+i/iJ69p+QoLjcC2LnArGY=@vger.kernel.org X-Gm-Message-State: APuU4Z/SpkMwzLzOhv0xnnZGuF2h80u8JLqbcP8M4+Fnk6aM17F1MZU8 /6Wqf5ZlCp4/vPlqL94g0Bw0HeyBvZDCmSceTJsB3ghDQpovrs9FhhOR X-Gm-Gg: AZFdTZeGv58a3Ke/yQSEWKnFMzDi7dOu1poqAysU+EpRslFQZ0fiI4vlj++y3NQOq5x 8VxpqzfigX5anFouZHJYCqcoLJHhx0cIuCQkDwXP0ALt1ccLVfIPld7zmEKSoe5y8V68jxTfgnD pPXMTEbvmSOdBaONmOBuyHiz9UIZp165S9BZy+VlhTT9O1p5dHpfulAhCsswkHb4IIy1nYCwcw1 0aYO9j4LR8JxUuLKq/ZVQCXxHo8qyeyjWrq+e0IRvKD7pr5UfhzhDdyoLRXMP4SJQg4z9aKXBSJ fIeag3uvWLExIth1KsMzrSiqPRVEwkQx2G5z6DvmN0lJ0xNc4sgvF8irfsejosKQNN3xHH+knSy XVa4TmEaH6Yf/KOD9Z1l7Grq1SoHQvrGIyKIdNQ/YiZ+XbmTfspBUXnrxqrfzKEHa6YVCWirXTr uALTqy18DQoJl31syJwMEp7kT3+odiHc4iwRTgCnFyf+xbZFYecKaAFs6lfX0/2HKTmW7Gy/sBj ohd3TXbGiYt4CwZYuWrnuWNYKm6MmVhFlhQkPPb+0bKzINkFracTUukSrR10NCPMwsAMX4u+uLk fICI60PXIO6yfR94zK1ddIrMtOcWUkbekhjuzPlFxxHGmWerpTyZwoMTBNHizmU= X-Received: by 2002:a05:6a00:4b03:b0:89e:3ff1:920d with SMTP id d2e1a72fcca58-8c87d01fba2mr42274092b3a.45.1796289225478; Thu, 03 Dec 2026 01:13:45 -0800 (PST) Received: from [192.168.1.34] ([103.215.237.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077bff6sm23277219b3a.3.2026.12.03.01.13.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 01:13:45 -0800 (PST) Message-ID: <7da217b2-f359-4336-8a8a-faf67c4f298f@gmail.com> Date: Thu, 3 Dec 2026 14:43:42 +0530 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/7] commit-graph: verify all trailer hashes against the chain file To: Patrick Steinhardt , git@vger.kernel.org Cc: Junio C Hamano References: <20261120-pks-odb-pluggable-commit-graphs-v2-0-31f2341a9932@pks.im> <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im> Content-Language: en-US From: Kaartic Sivaraam In-Reply-To: <20261120-pks-odb-pluggable-commit-graphs-v2-1-31f2341a9932@pks.im> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/20/26 17:52, Patrick Steinhardt wrote: > > The fact that we perform the validation when linking means that the > check of trailer hashes is delayed: we only verify the hash of layer N > when linking layer N+1 onto it. That of course doesn't make sense, as we > will then happily use a layer with a mismatching hash while dropping all > layers built on top of that. What we should do though is to cut the > commit graph chain at the first mismatching layer. > > Furthermore, this also means that we never verify the trailer hash of > the topmost layer: there is nothing to link onto that layer, and hence > we never verify it. > > Fix this by verifying each layer directly after loading it. > Nit: "verify ... trailer hashes" made me think at first that we now validate the checksum of each layer on load. On some investigation, I understand that we don't do that to keep the commit graph load performant. I wonder if we could phrase that explicitly as follows to make it less ambiguous: Fix this by checking each layer's trailer against the chain file. > > diff --git a/commit-graph.c b/commit-graph.c > index da65cd3deb9..0c75939910d 100644 > --- a/commit-graph.c > +++ b/commit-graph.c > @@ -580,8 +580,6 @@ static int add_graph_to_chain(struct commit_graph *g, > struct object_id *oids, > int n) > { > - struct commit_graph *cur_g = chain; > - > if (n && !g->chunk_base_graphs) { > warning(_("commit-graph has no base graphs chunk")); > return 0; > @@ -595,15 +593,11 @@ static int add_graph_to_chain(struct commit_graph *g, > while (n) { > n--; > > - if (!cur_g || > - !oideq(&oids[n], &cur_g->oid) || > - !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n), > + if (!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n), > g->hash_algo)) { > warning(_("commit-graph chain does not match")); > return 0; > } > - > - cur_g = cur_g->base_graph; > } > > if (chain) { > @@ -682,13 +676,19 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb, > free(graph_name); > > if (g) { > - if (add_graph_to_chain(g, graph_chain, oids, i)) { > + /* > + * Verify that the loaded commit graph's > + * trailer matches the chain file. > + */ > + if (!oideq(&g->oid, &oids[i])) { > + warning(_("commit-graph chain does not match")); > + } else if (add_graph_to_chain(g, graph_chain, oids, i)) { > graph_chain = g; > valid = 1; > - } else { > - commit_graph_free(g); > } > > + if (!valid) > + commit_graph_free(g); > break; > } > } The change itself looks fine to me. > diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh > index bf7ba0e5580..aea89f42fa1 100755 > --- a/t/t5324-split-commit-graph.sh > +++ b/t/t5324-split-commit-graph.sh > @@ -16,9 +16,6 @@ test_expect_success 'setup repo' ' > infodir="$objdir/info" && > graphdir="$infodir/commit-graphs" && > test_oid_cache <<-EOM > - shallow sha1:2132 > - shallow sha256:2436 > - > base sha1:1408 > base sha256:1528 > > @@ -275,13 +272,17 @@ corrupt_file() { > printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc > } > > -test_expect_success 'verify hashes along chain, even in shallow' ' > +corrupt_trailer() { > + corrupt_file "$1" $(($(test_file_size "$1") - 7)) "corrupt" > +} > + > +test_expect_success PERL_TEST_HELPERS 'verify hashes along chain, even in shallow' ' Nit: Given the change from testing the base commit rather than the tip commit with 'verify --shallow', can name this 'verify --shallow detects corrupt tip layer' ? > git clone --no-hardlinks . verify && > ( > cd verify && > git commit-graph verify && > - base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph && > - corrupt_file "$base_file" $(test_oid shallow) "\01" && > + tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph && > + corrupt_chunk_file "$tip_file" OIDL 0 ff && > test_must_fail git commit-graph verify --shallow 2>test_err && > grep -v "^+" test_err >err && > test_grep "incorrect checksum" err Also, the corruption in base layer would still fail in '--shallow' even after this change. So, is it worth having a test to verify that? Something like: test_expect_success 'verify --shallow notices broken chain below tip' ' git clone --no-hardlinks . verify-broken-base && ( cd verify-broken-base && base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph && corrupt_trailer "$base_file" && test_must_fail git commit-graph verify --shallow 2>err && test_grep "commit-graph chain does not match" err ) ' -- Sivaraam