From patchwork Thu Sep 30 13:37:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13B0DC433EF for ; Thu, 30 Sep 2021 13:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF60E619E9 for ; Thu, 30 Sep 2021 13:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351563AbhI3NjR (ORCPT ); Thu, 30 Sep 2021 09:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351501AbhI3NjL (ORCPT ); Thu, 30 Sep 2021 09:39:11 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B339BC06176A for ; Thu, 30 Sep 2021 06:37:28 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id t16-20020a1c7710000000b003049690d882so8436605wmi.5 for ; Thu, 30 Sep 2021 06:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yPx0KT5jVhbA+IQtxng9p/dsLu1Psx4mXe9hAN36+5E=; b=CVyJzpeaqVfVn2WFPrj+2AIZHB4Nn5Qy3Hb4jRUqDxjE0cECYUMaf1DMg+mZYP+VXP 9lP2CSXdGqlZmv4LpvUCRqA83xUNpj+R9XAxoUHhAVZmp+4OFKDk1/9oo80h9dfQdTPa LMAkIvmIcXrxrh9UpKFH7sKoZqVOm/WnigRh28+GcRU1UNZ2ouSs1979v5VMZAGsK5UN 0F6pxPbmGxcHn0D+M8PykIvnebGSbSBPuUDa+jcndoEvBmuvzDd3w0ZYTdK8d9LqjWW2 yCYJCmASQCQVHuGk3yZMP3MiDUSMgkMKnbiIzOb9cSKeZpsG/jLk8Th5uBqyzinyca8b Z/jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yPx0KT5jVhbA+IQtxng9p/dsLu1Psx4mXe9hAN36+5E=; b=roGIEf23ApGeUSN4Znj9cFQbCZ8qJMmXzxvyv+mGkvmCKwQ0LF/rFNdG8CdV/sI67k N0H4rUziSQs7oc2GV4daGH02eI2zxYA/PcA+kDyAP6BX8GlchhntXO58V9LJtczXe0h+ 5moWO1Id3pRwYPENdCAuIwdvR1Hd+1tvETA5K3LhfBQyxdTTUlial4WS5Qd4MK1urz2m sK9+OZRwqyQMGSY7y8To6fI1A+7VfOiw23Gvl0gB5MvCthCAmtRm7kxI6mDMJ84hDVcQ 2umUDPszH0P1n9FAlLJVrJEMp9bnqLzoCOQ+OgJx2hw0Zf3wqHu6jJEYhNKUHTGicf+Y +zSA== X-Gm-Message-State: AOAM533zIWUD2M2tt0voxA0Uv8c7f3NgnptTI3kdIjuGA0pUQvds9QTo LL9CfBfmR/YmcnOcu8R78SNyWLZQaPu/vqUy X-Google-Smtp-Source: ABdhPJytCdiDsRf/k3bKTAmVgCJKrPfrnDbnLSWzfat+Khb3dHVpCDg3T/POa6iMXz8VMmF8Pn5DoQ== X-Received: by 2002:a05:600c:22da:: with SMTP id 26mr5274943wmg.100.1633009047085; Thu, 30 Sep 2021 06:37:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 01/17] fsck tests: add test for fsck-ing an unknown type Date: Thu, 30 Sep 2021 15:37:06 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a blindspot in the fsck tests by checking what we do when we encounter an unknown "garbage" type produced with hash-object's --literally option. This behavior needs to be improved, which'll be done in subsequent patches, but for now let's test for the current behavior. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 5071ac63a5b..969bfbbdd8f 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -865,4 +865,21 @@ test_expect_success 'detect corrupt index file in fsck' ' test_i18ngrep "bad index file" errors ' +test_expect_success 'fsck hard errors on an invalid object type' ' + git init --bare garbage-type && + ( + cd garbage-type && + + empty=$(git hash-object --stdin -w -t blob err.expect <<-\EOF && + fatal: invalid object type + EOF + test_must_fail git fsck >out 2>err && + test_cmp err.expect err && + test_must_be_empty out + ) +' + test_done From patchwork Thu Sep 30 13:37:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F9E4C433FE for ; Thu, 30 Sep 2021 13:37:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 189CD611C7 for ; Thu, 30 Sep 2021 13:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351538AbhI3NjU (ORCPT ); Thu, 30 Sep 2021 09:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351492AbhI3NjM (ORCPT ); Thu, 30 Sep 2021 09:39:12 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 944E4C06176C for ; Thu, 30 Sep 2021 06:37:29 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id g19-20020a1c9d13000000b003075062d4daso4394947wme.0 for ; Thu, 30 Sep 2021 06:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lgUL95zxjbeepJQB91L6BSlwNdgnBquzLCEeIVCAxvw=; b=Nw30LktL3S/5pjTnr7LVZX7xwWqRiVN84COiaB4nVj1MmN7rYw2cUSmzCh22wFwvad OJJNb1hesPXpzhHcff3F5A1gnf3p243xmeoSycE7j0xuW6uwp99iOmWUk32SAofL5Aus vtIy7Lz2d/IzkupFFL3Y0EL/JmhKYEBX/bpKzncjwnjqAQodcRYQX5P4uN153f8AHCq0 ek7AbpgPop332Ce/G/53yl9yPxCXxtIxMfu7h7ayjvGC063KSkkT5bwVgYzxiy07SRfy Ey/CpB00bkO1+t/y2DfCE21oB8IRFmgsiQ+ZdjTBZs9OWwqRPEdIZutDhVy1oYvmygtC QfhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lgUL95zxjbeepJQB91L6BSlwNdgnBquzLCEeIVCAxvw=; b=19EY3kCpauG8xJ4Ddl+yTqhJRfSencQ692OQRIpu8syXbHhnpgYERNQfHQijoW6M3B 6nWee78YRpp0ZuSpMOjr+SnRFwxsj8UoquOR0g+yHo2bxggyaGVuot6Y3lR45n8cJALv Mc6dynqUe5B34JUzXKsXqSJsvmZoS2duAZsTVJ/luM8/eBTXjW1Q6DfETv758wJ6tlGi hq1RvjRnk3a6RY/AmTFLZVbRi3hn4aLMBT9lNxrzHQ03dEag1AtZ/Fh29krw4uDtrJrS frlfs6iWZXvfEkGT3C2i8NsM2FiU2veSM7nlv1aKG7cpKpOm3KjxYLBrSdroVq5RqIzZ oiTw== X-Gm-Message-State: AOAM532jcuUseO8jxJq7hFsTXKCbepovpkfp3AqKHVHCs/7E9wwMt8mH uVsqhjFyGwSxJeARI38c44fLPkcax/SypqxW X-Google-Smtp-Source: ABdhPJzVR9p5vblyUmwHh3lO+dJN3wCCwqUwh6WcU0iY9RNOKLNtQKgYP35KJj9PxtqoxXC6zBdHlA== X-Received: by 2002:a1c:7f11:: with SMTP id a17mr15972508wmd.166.1633009047971; Thu, 30 Sep 2021 06:37:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 02/17] fsck tests: refactor one test to use a sub-repo Date: Thu, 30 Sep 2021 15:37:07 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor one of the fsck tests to use a throwaway repository. It's a pervasive pattern in t1450-fsck.sh to spend a lot of effort on the teardown of a tests so we're not leaving corrupt content for the next test. We can instead use the pattern of creating a named sub-repository, then we don't have to worry about cleaning up after ourselves, nobody will care what state the broken "hash-mismatch" repository is after this test runs. See [1] for related discussion on various "modern" test patterns that can be used to avoid verbosity and increase reliability. 1. https://lore.kernel.org/git/87y27veeyj.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 969bfbbdd8f..f8edd15abf8 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -48,24 +48,25 @@ remove_object () { rm "$(sha1_file "$1")" } -test_expect_success 'object with bad sha1' ' - sha=$(echo blob | git hash-object -w --stdin) && - old=$(test_oid_to_path "$sha") && - new=$(dirname $old)/$(test_oid ff_2) && - sha="$(dirname $new)$(basename $new)" && - mv .git/objects/$old .git/objects/$new && - test_when_finished "remove_object $sha" && - git update-index --add --cacheinfo 100644 $sha foo && - test_when_finished "git read-tree -u --reset HEAD" && - tree=$(git write-tree) && - test_when_finished "remove_object $tree" && - cmt=$(echo bogus | git commit-tree $tree) && - test_when_finished "remove_object $cmt" && - git update-ref refs/heads/bogus $cmt && - test_when_finished "git update-ref -d refs/heads/bogus" && +test_expect_success 'object with hash mismatch' ' + git init --bare hash-mismatch && + ( + cd hash-mismatch && - test_must_fail git fsck 2>out && - test_i18ngrep "$sha.*corrupt" out + oid=$(echo blob | git hash-object -w --stdin) && + old=$(test_oid_to_path "$oid") && + new=$(dirname $old)/$(test_oid ff_2) && + oid="$(dirname $new)$(basename $new)" && + + mv objects/$old objects/$new && + git update-index --add --cacheinfo 100644 $oid foo && + tree=$(git write-tree) && + cmt=$(echo bogus | git commit-tree $tree) && + git update-ref refs/heads/bogus $cmt && + + test_must_fail git fsck 2>out && + grep "$oid.*corrupt" out + ) ' test_expect_success 'branch pointing to non-commit' ' From patchwork Thu Sep 30 13:37:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB3DFC433F5 for ; Thu, 30 Sep 2021 13:37:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3985611C7 for ; Thu, 30 Sep 2021 13:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351402AbhI3NjS (ORCPT ); Thu, 30 Sep 2021 09:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351538AbhI3NjN (ORCPT ); Thu, 30 Sep 2021 09:39:13 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7851C06176E for ; Thu, 30 Sep 2021 06:37:30 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id t16-20020a1c7710000000b003049690d882so8436690wmi.5 for ; Thu, 30 Sep 2021 06:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qm9f25krk0upFswiwr84ZshPl1GjzPVuBelyJiasPpI=; b=j8t5SeUWpdTh+++cklHuaTS3kT74KKpUMTf+3KYT4sJwH5mvCsMSWCH0FU0wI5/Hr7 7QqhfTiykRyzgeRDlDkYxL6cn+Fea60Sf0Fjt/8dkxrQ6jPatrfk1SMY4WxTNCtqI88X gCaRt0k/G+qPZfn4Pv/oShrUj8NhyfRN5Zs7SExZ+S92aL4tERcUP1BEL6SFxoeZHos4 84wPuJvwT6BmT4w1rbgROMKUX/iWXlwI/t6cVi7nTiX5N6H41gY+5VbSFnKjKR9JMInh FfWcF6fHmUkmd2DPPbDd32Jd2+pWOSa/OgqTH20cbphdzAu6P0v7CkitV3TjO2r2ucKW GVcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qm9f25krk0upFswiwr84ZshPl1GjzPVuBelyJiasPpI=; b=oIYhwNLnIw6Ijzi3LqhMniKQ4MSEKGFNBJet8urPmiRkPo3ic1kZ/51Yt/o+Myhk/8 zuyBVJ9+kZ4e9lR/lQ1bWhIBEAMST9m6Kzoq7RNQe04qF/VjOTd63dgPeC/QWW9ZH90f qehAoQCevZb7h8stSb8yLBj+oZwdYSEQXBVq4KZKsS7Fm43CKOefhJgO975qdiLeAsKB B97HBaSdT0TxwIPxUfElyNAA1NhpLobOZugcPqXfAvbuSex8X2910qcg88dArUSnL8dd UTzIhybhjw7JyHdXlrsnKSryXwM2hKcDYMOiMuaSNZsC5ZuMNAQFMNqqriTmxE+Gnwjw A2Ww== X-Gm-Message-State: AOAM533PByd0Ur45iDp9VISTBZ9KtqSAExcegGunewHWqLAMJdGnKO7D +SdPzoA/arPjtyruxcX/CQaxD752su+ronpl X-Google-Smtp-Source: ABdhPJwt7QRvAXFYHm9D9BgoTOJxCIYljvOTIME5gRtM/rVCpysM6NHGf8aiAHJ+aB91bDRzw5rQNw== X-Received: by 2002:a05:600c:410b:: with SMTP id j11mr15876353wmi.142.1633009048781; Thu, 30 Sep 2021 06:37:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 03/17] fsck tests: test current hash/type mismatch behavior Date: Thu, 30 Sep 2021 15:37:08 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If fsck we move an object around between .git/objects/?? directories to simulate a hash mismatch "git fsck" will currently hard die() in object-file.c. This behavior will be fixed in subsequent commits, but let's test for it as-is for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index f8edd15abf8..175ed304637 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -69,6 +69,30 @@ test_expect_success 'object with hash mismatch' ' ) ' +test_expect_success 'object with hash and type mismatch' ' + git init --bare hash-type-mismatch && + ( + cd hash-type-mismatch && + + oid=$(echo blob | git hash-object -w --stdin -t garbage --literally) && + old=$(test_oid_to_path "$oid") && + new=$(dirname $old)/$(test_oid ff_2) && + oid="$(dirname $new)$(basename $new)" && + + mv objects/$old objects/$new && + git update-index --add --cacheinfo 100644 $oid foo && + tree=$(git write-tree) && + cmt=$(echo bogus | git commit-tree $tree) && + git update-ref refs/heads/bogus $cmt && + + cat >expect <<-\EOF && + fatal: invalid object type + EOF + test_must_fail git fsck 2>actual && + test_cmp expect actual + ) +' + test_expect_success 'branch pointing to non-commit' ' git rev-parse HEAD^{tree} >.git/refs/heads/invalid && test_when_finished "git update-ref -d refs/heads/invalid" && From patchwork Thu Sep 30 13:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 283BDC433F5 for ; Thu, 30 Sep 2021 13:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 024AA611C7 for ; Thu, 30 Sep 2021 13:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351649AbhI3NjW (ORCPT ); Thu, 30 Sep 2021 09:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351502AbhI3NjO (ORCPT ); Thu, 30 Sep 2021 09:39:14 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C653DC06176D for ; Thu, 30 Sep 2021 06:37:31 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d21so10083898wra.12 for ; Thu, 30 Sep 2021 06:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qzZU389iEsX02dmEHR5Hs1z99Jc0DOl0Cwu0DEiunQc=; b=PInKCfBUCz9B5kUpa33XiR/BWLLRnLCcd1DvJ25MoMDQHcDZ5C24kI8ddAK/w0L05y d3Dw6d4/SVoyVTQ5jvB4dWD4rn1kbULr+c6QSdUYcE90mBgwQPpeDdHw2p00vwbZc/Rq 0ByCSlKQsJJXrGfe6PN6+xWVdAGaIer8CI9FUIiICkym5ndZ+tOVpzzDlIoHgUEADAW+ zfOqoS7FRsimsH6VwD4ohxf2CekboCxj1z2IDt0tJNGq4fGzafjhi9vlgvEF6E+K3vGN Gi9y2F7xpiBxp4nCk9SxZkLQmdPwRg2dHdEW/XJxo6PMsrE3CFTyofNdNlvl7ODV6ZPb Tqdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qzZU389iEsX02dmEHR5Hs1z99Jc0DOl0Cwu0DEiunQc=; b=i8aRK0gbQDm+hWkRxi00CN6G4ciRhfS91BVscyq7Ezl9LN4sova//Fww53I+ezU8bi riahCGFSvXN7vPGbmmkCB/+t2Rk5HTU3qx18LWG6A5kdzglitHJZH5Mr5Je7pCpw6un5 0qyeylPKsVvIWKswnrME15mPnEhIdEo36fOFj2OdSncwa8MfnvznZXsYzXIBE4BbeUYI okFmDNb93bPqVn+7Q7C0Chtu5PFBCqwx77YviA59m2fkcVFlbN5lS6y0qzwiK3bn/W3A jmnnH19n1cvVpWBIC+/suiO4HwxkGFZ3Xfg43VsLgKO7W4Yrae2HzhC2w+wdkTuH5qvV SQMg== X-Gm-Message-State: AOAM532I7l+2pyPOrqlmsB8iYJfHOBD/pVv94qfojfnwhgeP2GSrsg// EDgdJXKyLa87gIu+bp/exaq0O83pgGvDtzuc X-Google-Smtp-Source: ABdhPJzgvNhTyOsH0tzcAtl81OVY9DxG7lsANjCYYHz8+BbbhgZxIwSexuVz4BUIUl4SrRRquScYfw== X-Received: by 2002:a5d:67cc:: with SMTP id n12mr6069930wrw.381.1633009050150; Thu, 30 Sep 2021 06:37:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 04/17] fsck tests: test for garbage appended to a loose object Date: Thu, 30 Sep 2021 15:37:09 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There wasn't any output tests for this scenario, let's ensure that we don't regress on it in the changes that come after this. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 175ed304637..bd696d21dba 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -93,6 +93,26 @@ test_expect_success 'object with hash and type mismatch' ' ) ' +test_expect_success POSIXPERM 'zlib corrupt loose object output ' ' + git init --bare corrupt-loose-output && + ( + cd corrupt-loose-output && + oid=$(git hash-object -w --stdin --literally >$oidf && + + cat >expect.error <<-EOF && + error: garbage at end of loose object '\''$oid'\'' + error: unable to unpack contents of ./$oidf + error: $oid: object corrupt or missing: ./$oidf + EOF + test_must_fail git fsck 2>actual && + grep ^error: actual >error && + test_cmp expect.error error + ) +' + test_expect_success 'branch pointing to non-commit' ' git rev-parse HEAD^{tree} >.git/refs/heads/invalid && test_when_finished "git update-ref -d refs/heads/invalid" && From patchwork Thu Sep 30 13:37:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0F10C433F5 for ; Thu, 30 Sep 2021 13:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB7E7619E5 for ; Thu, 30 Sep 2021 13:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351658AbhI3NjZ (ORCPT ); Thu, 30 Sep 2021 09:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351486AbhI3NjP (ORCPT ); Thu, 30 Sep 2021 09:39:15 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C959C06176A for ; Thu, 30 Sep 2021 06:37:32 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id x20so10111651wrg.10 for ; Thu, 30 Sep 2021 06:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xi8Yw8Zz+Pnv32fJpGaQ5ZIgCJdjep8vmnOjlAz8n1E=; b=IDs/YmkMy9F/3tP07urkBsQ9f9QwERYSX3sBMcgF8Up4fut1mrR8VoUh0nnPsA9HoG Vt3GxPI3H3itP8JzUSObl0gy0vlp2qnQdbHN0UEDKIdP7/BmtyPUNUbX1+O+dfrNWcE0 GrHo0f8yv1jzIiBK8b99rD1PK0Fu1UwVJsR0dWVAiaM/C9EvEsVtajPoK3uueunKOSXb 5IQmv7svwjefhdK0qYsQ6Yz/xBAIeLLhvHYlwilo50fVJCve5+xoz7WI2Kyze1sU+R+a aGzVvSzivY3uO5YFptpqhf86Nkwho7HgWrtGT58u2ujOgvW0BFwGKbtO3YxbKGEV+ue4 l4OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xi8Yw8Zz+Pnv32fJpGaQ5ZIgCJdjep8vmnOjlAz8n1E=; b=3dYw+ugidUULENl4ydmG+gmCgfQieWdCVqPcqpUhXQtxh3fL7FYUmsM0z3iIFzJ/SH JxwapmkMMYsW/BkHIk0naGcu/nvN/gJURICzStBUC8j54n1kZHlp1njjqjveKDhdkmn/ pzjg3ALKIBfmNLmxZn0jgAmHhn28CnLk33lEOElhtVT7VIqtdJM6GTpa8LWd4iM4fLlS z9QX7Nu7t/7SO4SlPXJSplcfhRns8BP11iTZL/DQFdU3IkzLLxtvRFAVxIFw7JU919DM ulcoeEJzJShG1X+3WZTVkJPmWOO73Hm8btsMtI6C41WM+V6eW9AymCVYiE56xG/yw9/d Bobg== X-Gm-Message-State: AOAM533c+kdyC2zWvcBQK/am7/dosJAs3d9MwMPhWi8V9UFHF8S33CIF ezpmp66zBl4drj5wf6T2uffdq7C/pHMFdjER X-Google-Smtp-Source: ABdhPJy0eBKUjStgeb3hHtmry/C8w/vNIr7hxRnmfDEFJl06jht+91gWl/WjxiNvOmXUqw/4YFV2qA== X-Received: by 2002:a5d:64a7:: with SMTP id m7mr6348192wrp.171.1633009051005; Thu, 30 Sep 2021 06:37:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 05/17] cat-file tests: move bogus_* variable declarations earlier Date: Thu, 30 Sep 2021 15:37:10 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the short/long bogus bogus object type variables into a form where the two sets can be used concurrently. This'll be used by subsequently added tests. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 18b3779ccb6..ea6a53d425b 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -315,36 +315,39 @@ test_expect_success '%(deltabase) reports packed delta bases' ' } ' -bogus_type="bogus" -bogus_content="bogus" -bogus_size=$(strlen "$bogus_content") -bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin) +test_expect_success 'setup bogus data' ' + bogus_short_type="bogus" && + bogus_short_content="bogus" && + bogus_short_size=$(strlen "$bogus_short_content") && + bogus_short_sha1=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) && + + bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" && + bogus_long_content="bogus" && + bogus_long_size=$(strlen "$bogus_long_content") && + bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin) +' test_expect_success "Type of broken object is correct" ' - echo $bogus_type >expect && - git cat-file -t --allow-unknown-type $bogus_sha1 >actual && + echo $bogus_short_type >expect && + git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual && test_cmp expect actual ' test_expect_success "Size of broken object is correct" ' - echo $bogus_size >expect && - git cat-file -s --allow-unknown-type $bogus_sha1 >actual && + echo $bogus_short_size >expect && + git cat-file -s --allow-unknown-type $bogus_short_sha1 >actual && test_cmp expect actual ' -bogus_type="abcdefghijklmnopqrstuvwxyz1234679" -bogus_content="bogus" -bogus_size=$(strlen "$bogus_content") -bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin) test_expect_success "Type of broken object is correct when type is large" ' - echo $bogus_type >expect && - git cat-file -t --allow-unknown-type $bogus_sha1 >actual && + echo $bogus_long_type >expect && + git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual && test_cmp expect actual ' test_expect_success "Size of large broken object is correct when type is large" ' - echo $bogus_size >expect && - git cat-file -s --allow-unknown-type $bogus_sha1 >actual && + echo $bogus_long_size >expect && + git cat-file -s --allow-unknown-type $bogus_long_sha1 >actual && test_cmp expect actual ' From patchwork Thu Sep 30 13:37:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A2DFC433EF for ; Thu, 30 Sep 2021 13:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19A4C619E9 for ; Thu, 30 Sep 2021 13:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351667AbhI3Nj1 (ORCPT ); Thu, 30 Sep 2021 09:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351644AbhI3NjR (ORCPT ); Thu, 30 Sep 2021 09:39:17 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C41AC06176D for ; Thu, 30 Sep 2021 06:37:34 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id b204-20020a1c80d5000000b0030cd967c674so1793784wmd.0 for ; Thu, 30 Sep 2021 06:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rWN+RH+Zw345gEiuKX4KhLTtLQmPsmRhJKjj02eTL44=; b=K28iqKLWWlTrRF/FUZWpmR3u7fWJXwqZ55XdECnoCek1JaihESH6EN/JHzSnEOywhn V9KC3O7PI3ZEFUtImVyGFcERnSMKTsdCPAE6NGxBvacKEyL5S5lPjjoj2F4Z4coJuoY6 W0q5CawJ2HqUSnESe5Xn2k3F0RPKa7TZUT8lOY20JKWdCN/wv+X+k3Dp3YOOXFlE+hO9 VDXyLXItZoQtQ+erMEi5nGe9HeZhiYtmkRIOVvCLFtP7WEfPy4i2l/+Yx5sY+BpPS9Js 16zzXZggbCset0ND8t9XhgBudZrJTN9wK3KHFAGJgnkZLrdQoaTM6ZHTSs20SfjJRQIS P2OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rWN+RH+Zw345gEiuKX4KhLTtLQmPsmRhJKjj02eTL44=; b=iWgJXwcjMscLuzmWxVxserESEnjQ0G+XqweRfFH4JRWyWf07YrG74QJ10fGkPXHD/L qRMI6yxJX/dzMyRdSBCB63byd53W8uPUXHa9YTgGvelO0IxLYuXG2p+lE0f7em8fJdVK iPtcXrkXOwHaLWbJEEZ/MDv7BIZ25/ixTqdVU2dqbqFb83LUKrFw2XiQDz5Tzf8+6LZU nuXJ0x0WlgAdLaAjYiUpFWmjnr8x1wnD16+f9NWDt2qsLic7iCV1KKoFGi/M/gwXz3SU rsp8U8i+6v1I4Brx91LYIDNONOMx0N7kWBVk2N5EcMnzL+oDTyiEE/B9vBCIlod38NwR m5Iw== X-Gm-Message-State: AOAM531HppwJpQqvRGR5KuB93LPdmRS68rQR/SNnyVIE0h7IeyNV2F5g ZyXAc2fTWSUZqSBtw1ahbivTcaRvFGlPdz9W X-Google-Smtp-Source: ABdhPJwPOGFT7ta+j3Bel5IuTvqiCsrWHEVQEu2aIyF7EjYsMT7d1ae3ISIRgZGmmnESe1j48ji91w== X-Received: by 2002:a7b:c056:: with SMTP id u22mr5484967wmc.15.1633009052046; Thu, 30 Sep 2021 06:37:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 06/17] cat-file tests: test for missing/bogus object with -t, -s and -p Date: Thu, 30 Sep 2021 15:37:11 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we look up a missing object with cat_one_file() what error we print out currently depends on whether we'll error out early in get_oid_with_context(), or if we'll get an error later from oid_object_info_extended(). The --allow-unknown-type flag then changes whether we pass the "OBJECT_INFO_ALLOW_UNKNOWN_TYPE" flag to get_oid_with_context() or not. The "-p" flag is yet another special-case in printing the same output on the deadbeef OID as we'd emit on the deadbeef_short OID for the "-s" and "-t" options, it also doesn't support the "--allow-unknown-type" flag at all. Let's test the combination of the two sets of [-t, -s, -p] and [--{no-}allow-unknown-type] (the --no-allow-unknown-type is implicit in not supplying it), as well as a [missing,bogus] object pair. This extends tests added in 3e370f9faf0 (t1006: add tests for git cat-file --allow-unknown-type, 2015-05-03). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/oid-info/oid | 2 ++ t/t1006-cat-file.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/t/oid-info/oid b/t/oid-info/oid index a754970523c..7547d2c7903 100644 --- a/t/oid-info/oid +++ b/t/oid-info/oid @@ -27,3 +27,5 @@ numeric sha1:0123456789012345678901234567890123456789 numeric sha256:0123456789012345678901234567890123456789012345678901234567890123 deadbeef sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef deadbeef sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef +deadbeef_short sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbee +deadbeef_short sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index ea6a53d425b..abf57339a29 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -327,6 +327,81 @@ test_expect_success 'setup bogus data' ' bogus_long_sha1=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin) ' +for arg1 in '' --allow-unknown-type +do + for arg2 in -s -t -p + do + if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p" + then + continue + fi + + + test_expect_success "cat-file $arg1 $arg2 error on bogus short OID" ' + cat >expect <<-\EOF && + fatal: invalid object type + EOF + + if test "$arg1" = "--allow-unknown-type" + then + git cat-file $arg1 $arg2 $bogus_short_sha1 + else + test_must_fail git cat-file $arg1 $arg2 $bogus_short_sha1 >out 2>actual && + test_must_be_empty out && + test_cmp expect actual + fi + ' + + test_expect_success "cat-file $arg1 $arg2 error on bogus full OID" ' + if test "$arg2" = "-p" + then + cat >expect <<-EOF + error: unable to unpack $bogus_long_sha1 header + fatal: Not a valid object name $bogus_long_sha1 + EOF + else + cat >expect <<-EOF + error: unable to unpack $bogus_long_sha1 header + fatal: git cat-file: could not get object info + EOF + fi && + + if test "$arg1" = "--allow-unknown-type" + then + git cat-file $arg1 $arg2 $bogus_short_sha1 + else + test_must_fail git cat-file $arg1 $arg2 $bogus_long_sha1 >out 2>actual && + test_must_be_empty out && + test_cmp expect actual + fi + ' + + test_expect_success "cat-file $arg1 $arg2 error on missing short OID" ' + cat >expect.err <<-EOF && + fatal: Not a valid object name $(test_oid deadbeef_short) + EOF + test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual && + test_must_be_empty out + ' + + test_expect_success "cat-file $arg1 $arg2 error on missing full OID" ' + if test "$arg2" = "-p" + then + cat >expect.err <<-EOF + fatal: Not a valid object name $(test_oid deadbeef) + EOF + else + cat >expect.err <<-\EOF + fatal: git cat-file: could not get object info + EOF + fi && + test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual && + test_must_be_empty out && + test_cmp expect.err err.actual + ' + done +done + test_expect_success "Type of broken object is correct" ' echo $bogus_short_type >expect && git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual && From patchwork Thu Sep 30 13:37:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3DBFC4332F for ; Thu, 30 Sep 2021 13:37:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABA4E619E9 for ; Thu, 30 Sep 2021 13:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351680AbhI3Nj2 (ORCPT ); Thu, 30 Sep 2021 09:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351645AbhI3NjR (ORCPT ); Thu, 30 Sep 2021 09:39:17 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ADEBC06176F for ; Thu, 30 Sep 2021 06:37:34 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id q127-20020a1ca785000000b0030cb71ea4d1so4383206wme.1 for ; Thu, 30 Sep 2021 06:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rzl7K7e7Xkgw/tpKZQmu0vjtXUqb58hGxXcRzkRBsIM=; b=hW4qcMy065EYAOhGz/Tj0BK28LYOun4hSaspH40R+ZguTpsPptwXMKkGo1yND8AAME +sDDUz5CosZdhJGAcHCSxjKLNhbr7bMQrxwVyer5ihDxwrPSB+vO6lHor+RZDpn4tlrR ymiYpxyojI02R2VuiKW8c9R0q69VlbRJqSA060Yhc90NM0HGj7nBBC13GKKERZwUWLPm g0hR90mZaVkSmKg4Zkyw3SWWeEEpGX1F2N7cvXacgGgDeelv+tHo9fgrNT1pdJXKgIxv Z7/AY74by+fNVBmACBwuThCNeMLYs9kjju44oJaYXv8ot6Fpo3yLQIQm27rS1x3GrX0r IWpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rzl7K7e7Xkgw/tpKZQmu0vjtXUqb58hGxXcRzkRBsIM=; b=548YsMqS7W1AIcgHvbEF2xfEbBkBKz6IgLv4QJQCwP9jj/tl0hDmeIF75SyRfV1thX PIGr8wWRMQrlaqAcm+KX6ct4OgzSehUBSjO/3nHFjoGKcs4hC3MghXJrtHLsiLjZCXvD /Xt7K0RyKy+aLeQfTJyZV23AmHqwnq5VBvGctJ08INQo8vwv2e8x/lCdlsaZ+YMFn5Bd bA6rmVEXOdhgh8KHXpJRpEzg4WZgUkDm1myfmVm4h04lvhgKfwlnPokPtnKFj64XvMD+ AVpdeBcwIx9J6lNr/V+4VM45ilaERpjou1eJbuupwPOt3TSeHQtiDNZpMABbLf871AMu 6hEg== X-Gm-Message-State: AOAM531UQ/4Zsvz/G6ikPni6eCmKorBPEyswWfqublh1rtLBah1C9Nd2 uDN8eL+CiNqwI5JnvoHiVO4FBtIFoV/WfT7k X-Google-Smtp-Source: ABdhPJzNyEwpPP0JS9C67ce9+OP+WCMBuOVXiDRlK886I9wWfBa3ynv6HJQJjeIwgNNG0XF3zrPzVA== X-Received: by 2002:a7b:ce98:: with SMTP id q24mr5427229wmj.33.1633009052877; Thu, 30 Sep 2021 06:37:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 07/17] cat-file tests: add corrupt loose object test Date: Thu, 30 Sep 2021 15:37:12 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a blindspot in the tests for "cat-file" (and by proxy, the guts of object-file.c) by testing that when we can't decode a loose object with zlib we'll emit an error from zlib.c. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index abf57339a29..15774979ad3 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -426,6 +426,58 @@ test_expect_success "Size of large broken object is correct when type is large" test_cmp expect actual ' +test_expect_success 'cat-file -t and -s on corrupt loose object' ' + git init --bare corrupt-loose.git && + ( + cd corrupt-loose.git && + + # Setup and create the empty blob and its path + empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) && + git hash-object -w --stdin other.blob && + other_blob=$(git hash-object -w --stdin out.expect <<-EOF && + 0 + EOF + git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual && + test_must_be_empty err.actual && + test_cmp out.expect out.actual && + + # Swap the two to corrupt the repository + mv -f "$other_path" "$empty_path" && + test_must_fail git fsck 2>err.fsck && + grep "hash mismatch" err.fsck && + + # confirm that cat-file is reading the new swapped-in + # blob... + cat >out.expect <<-EOF && + blob + EOF + git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual && + test_must_be_empty err.actual && + test_cmp out.expect out.actual && + + # ... since it has a different size now. + cat >out.expect <<-EOF && + 6 + EOF + git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual && + test_must_be_empty err.actual && + test_cmp out.expect out.actual && + + # So far "cat-file" has been happy to spew the found + # content out as-is. Try to make it zlib-invalid. + mv -f other.blob "$empty_path" && + test_must_fail git fsck 2>err.fsck && + grep "^error: inflate: data stream error (" err.fsck + ) +' + # Tests for git cat-file --follow-symlinks test_expect_success 'prep for symlink tests' ' echo_without_newline "$hello_content" >morx && From patchwork Thu Sep 30 13:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04738C433EF for ; Thu, 30 Sep 2021 13:37:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1786611C7 for ; Thu, 30 Sep 2021 13:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351660AbhI3Nj3 (ORCPT ); Thu, 30 Sep 2021 09:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351516AbhI3NjS (ORCPT ); Thu, 30 Sep 2021 09:39:18 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A075C06176A for ; Thu, 30 Sep 2021 06:37:35 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id u18so10134597wrg.5 for ; Thu, 30 Sep 2021 06:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZyrRUmELexY6Y8Mka4qYCfup65yQR3qTaI7B/PcebK4=; b=PGclwFJ3n7sVMJlP73H6sws7/W8evnBi8d5Rp5xq5KrlhXWDGe2bSn+i74kxT9i133 l9oNURSM43nOvQgKDQ2kdckkC97LfaxbCPSqgZ3ce5eF+R6SlynOd+K3v7SCIfKs3R/a OM/+6UnrlujSl6TuJh1VHZYn8ouE9ZhNNNarLtG9TM3kNCnAi/lREeWt26xaLOG1Rw8h X6mHdJj34KhnPRMRZxE9tDSsqso+jG8t33eqwcRXk1F8nwkGjw1ICyU1XbnChUlYyi/A NliAY0FkEMhZeNDcSQrtzJxyLnzY6CWp5ARRqlvF53hWFySk/aIff3Bj8BWLeVDPSg5w OzyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZyrRUmELexY6Y8Mka4qYCfup65yQR3qTaI7B/PcebK4=; b=uAhpbvQSQHSuDA9nEckTslhMLyyu2F3QsxAqNWJc8haRD+hhb+vG1NeFwdoq3XlEd+ X3ha1AFps0o5HVn54Yg5JfRCBJOF/CI6qStqWr5BVHBshN18bcaKY7lm3h+t16R7hldI oMu6OQvLKt/Ny7UwzwKM/LArfiWu3Fz+pFdQeqiZSbqYn6agDbLccLWsg9wzww77XX5+ PnFvk2pX530d5GyewGdAm2/PRX8dJnLI2uYInlDC85DOCOIvgHZNVO8JsFGp/Ek7xGDg t+2R5b1KzZeQQct6q8WENphQI7ZoEjtmW12Ulekpp94GdIuq4yQqypeMY8sKv7VKJdiN QZpw== X-Gm-Message-State: AOAM531Ax1U64qYQSt1BCNCZCZ7P/e108q2OZnya4EePzoR+RHrqDVUG vXSH4TKn1ffGdQfyCre6zQmIki03sUDkMU2u X-Google-Smtp-Source: ABdhPJyj5Oyxdj7b8cKn8e/muY2HghgK1P1uxlVM2hkAFPbe2ezM6+a0vvVnkqYWiveYWtYsCQ7+8g== X-Received: by 2002:adf:e84b:: with SMTP id d11mr6162345wrn.70.1633009053793; Thu, 30 Sep 2021 06:37:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 08/17] cat-file tests: test for current --allow-unknown-type behavior Date: Thu, 30 Sep 2021 15:37:13 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add more tests for the current --allow-unknown-type behavior. As noted in [1] I don't think much of this makes sense, but let's test for it as-is so we can see if the behavior changes in the future. 1. https://lore.kernel.org/git/87r1i4qf4h.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 15774979ad3..5b16c69c286 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -402,6 +402,67 @@ do done done +test_expect_success '-e is OK with a broken object without --allow-unknown-type' ' + git cat-file -e $bogus_short_sha1 +' + +test_expect_success '-e can not be combined with --allow-unknown-type' ' + test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1 +' + +test_expect_success '-p cannot print a broken object even with --allow-unknown-type' ' + test_must_fail git cat-file -p $bogus_short_sha1 && + test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1 +' + +test_expect_success ' does not work with objects of broken types' ' + cat >err.expect <<-\EOF && + fatal: invalid object type "bogus" + EOF + test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual && + test_cmp err.expect err.actual +' + +test_expect_success 'broken types combined with --batch and --batch-check' ' + echo $bogus_short_sha1 >bogus-oid && + + cat >err.expect <<-\EOF && + fatal: invalid object type + EOF + + test_must_fail git cat-file --batch err.actual && + test_cmp err.expect err.actual && + + test_must_fail git cat-file --batch-check err.actual && + test_cmp err.expect err.actual +' + +test_expect_success 'the --batch and --batch-check options do not combine with --allow-unknown-type' ' + test_expect_code 128 git cat-file --batch --allow-unknown-type expect <<-EOF && + $bogus_short_type + EOF + git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual && + test_cmp expect actual && + + # Create it manually, as "git replace" will die on bogus + # types. + head=$(git rev-parse --verify HEAD) && + test_when_finished "rm -rf .git/refs/replace" && + mkdir -p .git/refs/replace && + echo $head >.git/refs/replace/$bogus_short_sha1 && + + cat >expect <<-EOF && + commit + EOF + git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual && + test_cmp expect actual +' + test_expect_success "Type of broken object is correct" ' echo $bogus_short_type >expect && git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual && From patchwork Thu Sep 30 13:37:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CAE5C433EF for ; Thu, 30 Sep 2021 13:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D240611C7 for ; Thu, 30 Sep 2021 13:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351697AbhI3Njc (ORCPT ); Thu, 30 Sep 2021 09:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351647AbhI3NjT (ORCPT ); Thu, 30 Sep 2021 09:39:19 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0A34C06176A for ; Thu, 30 Sep 2021 06:37:36 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d26so10114564wrb.6 for ; Thu, 30 Sep 2021 06:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HaEnrTf+WYDy4A4BLJ+sYMdCPrP7roJKnxUMEepScV8=; b=fiSXwQosWLTRPKN5qFxnIrGg+dV2siRIIt/glA9UCwiTf6MjH+uJJ8DoAEprwu4Wva 6By3lCPAxG7u+QnEkTpeVUAcu939R/K2tRhqkEAFTU9QXot5wClSJY5/bKcWyR1+LJCT xhJl/duYfZicW9ya4K81ri7UXtO5hen/R5OZMQfFp6ly0A/lpOigiVQOfxk8SS/xuiTo s19z+D3Wtm72wafjTdHp2tAOVTfxNQCgiCA0Q7WA6Uzg0EEkAsdKfVViHCn79WJjrVu8 ner4DXP2BXP8RB/1IzIiUQ+kfHo81/Jnhp1fW0U+JXgVuvVqFSSwgAghtP0uc5p3j+8Y y7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HaEnrTf+WYDy4A4BLJ+sYMdCPrP7roJKnxUMEepScV8=; b=tjv+8DapaTVD9uWdPszN4F36uYyWbgqD04pE50BgGc3aOHzjt3V4BUNmTBtanvt+B2 0yq7KkaE6hCYvnLdU8FcsAwaAg3Dp8CiRV1i8Y0Z5LlirDY6mlPpNZRk19ioizKwzu8E aAfUgLJ6B3bmDidbgq6oSFb0eHSJwRMqhdUafUdLUbBkn0gqflBkl2lrLRh0j3lzR7Fn 7DXqWhdgRCrxuSMyZlhfsTstRJTkP9I+7HlHspuxyrNogiuuXgJGd3dVyZ7FFKJFq6lx L7xZeqf3fNTFNiQGSgAktN5MDAUJrpQrzv570QAAJE6t1tx9oN2tBiEOfXtSp0LX8ZaD 9cdg== X-Gm-Message-State: AOAM532Vj5/WwwJmgs5vHPq0VndskWOZVlVhEyIb/6TGOYJa2eAHTtdq CEnpNeDxo2C1GmBCqhORJN1IfakB7Qr1SczV X-Google-Smtp-Source: ABdhPJxbXutpdghxXkMmKPr1WN3VO1d8fClbDZ3kxe4D9Z+TO0TpOlZLN9hjsAmku5QUUjbyCtoEIA== X-Received: by 2002:adf:e4cc:: with SMTP id v12mr6164176wrm.95.1633009055130; Thu, 30 Sep 2021 06:37:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 09/17] object-file.c: don't set "typep" when returning non-zero Date: Thu, 30 Sep 2021 15:37:14 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the loose_object_info() function returns an error stop faking up the "oi->typep" to OBJ_BAD. Let the return value of the function itself suffice. This code cleanup simplifies subsequent changes. That we set this at all is a relic from the past. Before 052fe5eaca9 (sha1_loose_object_info: make type lookup optional, 2013-07-12) we would always return the type_from_string(type) via the parse_sha1_header() function, or -1 (i.e. OBJ_BAD) if we couldn't parse it. Then in a combination of 46f034483eb (sha1_file: support reading from a loose object of unknown type, 2015-05-03) and b3ea7dd32d6 (sha1_loose_object_info: handle errors from unpack_sha1_rest, 2017-10-05) our API drifted even further towards conflating the two again. Having read the code paths involved carefully I think this is OK. We are just about to return -1, and we have only one caller: do_oid_object_info_extended(). That function will in turn go on to return -1 when we return -1 here. This might be introducing a subtle bug where a caller of oid_object_info_extended() would inspect its "typep" and expect a meaningful value if the function returned -1. Such a problem would not occur for its simpler oid_object_info() sister function. That one always returns the "enum object_type", which in the case of -1 would be the OBJ_BAD. Having read the code for all the callers of these functions I don't believe any such bug is being introduced here, and in any case we'd likely already have such a bug for the "sizep" member (although blindly checking "typep" first would be a more common case). Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/object-file.c b/object-file.c index be4f94ecf3b..766ba88b851 100644 --- a/object-file.c +++ b/object-file.c @@ -1525,8 +1525,6 @@ static int loose_object_info(struct repository *r, git_inflate_end(&stream); munmap(map, mapsize); - if (status && oi->typep) - *oi->typep = status; if (oi->sizep == &size_scratch) oi->sizep = NULL; strbuf_release(&hdrbuf); From patchwork Thu Sep 30 13:37:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ED02C433FE for ; Thu, 30 Sep 2021 13:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F1DE619E9 for ; Thu, 30 Sep 2021 13:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351668AbhI3Njd (ORCPT ); Thu, 30 Sep 2021 09:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351492AbhI3NjU (ORCPT ); Thu, 30 Sep 2021 09:39:20 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5293C06176F for ; Thu, 30 Sep 2021 06:37:37 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d26so10114664wrb.6 for ; Thu, 30 Sep 2021 06:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EB2fZEVummt8748pmMRqI4GRZrL4BmqzBtvYUa20LUY=; b=kBJFBEPUYGSPLIk/pHFRyXxy6wJPT5jqYDgclAyZ0Mv9uuDkeqN/2bqkRPqp5Xsw+a W/tVZDonLQ3yhkxgY8h30Get0rP7fmbTD/AhFPsWO+LUOcL4+HoAAGQru2fOVJJpUskR fFKOrlFM2NME9QRCZ3p6NZSw1NSRs/PYbmi09yqk/RvI7GvVUhg2CLhRDKEqhNhHIYN5 dOyu+DjbCVTonm1r52dKRU6Li99sjQTfSHYj9GZPjHI7thxh1IwARo4gd4Pe7Qhzg2SZ dgN7cPu+8eO0dAKwOlELjDPyjctIrqCQZDsjaa45NxSkxgrzzGIqTxxUGGxOY4dQvMc9 sHAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EB2fZEVummt8748pmMRqI4GRZrL4BmqzBtvYUa20LUY=; b=BKJWzHGUVRYNCXJoJBTALP4unVakdhdvSUuaPcNTNAAbNPa6UUi3wmPCKsZVffnaNc Avhy/aX21YT1b8F8hymZROE0hDl4/WUl7/OMYrEcVM2MgX4s4e3F1vegtKP1aiRs5tY6 bZFfO2Js0wu8VgLJu9VHNt5MF7wGCWtH/vNZISBeGUIop/C/WYtX8YsbTcGtfL3X2MF0 IsFq4yc6Pmu+fX3dFwR+MNMYvtMvLY3rIUxxdRLCk4ZS9CahaDG8Wv3gEUj/k+RwkmIR bYhlD/V6OjGDcaaFRfKBg5OODS+z0SknpdYfBM2fiitMzgTuB9qF2Tvqs4w9/nvRIB6U e4sA== X-Gm-Message-State: AOAM532ka0yJwurQBK1tMh5haJFhirxrpEp5OrPJfDCUGDYsU2Eh4uOz /c9EppmmyC9hgaeHGlUloRbSGcQVm5wyV5Tn X-Google-Smtp-Source: ABdhPJwLST62fhaj1OTQxpQ8EK1NZn8bRrJ/Qn/Bnv6jsAS0Y9aYPmCEsDytCsbRjFOYvTqcyeEClw== X-Received: by 2002:adf:a499:: with SMTP id g25mr5747822wrb.239.1633009056137; Thu, 30 Sep 2021 06:37:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 10/17] object-file.c: return -1, not "status" from unpack_loose_header() Date: Thu, 30 Sep 2021 15:37:15 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Return a -1 when git_inflate() fails instead of whatever Z_* status we'd get from zlib.c. This makes no difference to any error we report, but makes it more obvious that we don't care about the specific zlib error codes here. See d21f8426907 (unpack_sha1_header(): detect malformed object header, 2016-09-25) for the commit that added the "return status" code. As far as I can tell there was never a real reason (e.g. different reporting) for carrying down the "status" as opposed to "-1". At the time that d21f8426907 was written there was a corresponding "ret < Z_OK" check right after the unpack_sha1_header() call (the "unpack_sha1_header()" function was later rename to our current "unpack_loose_header()"). However, that check was removed in c84a1f3ed4d (sha1_file: refactor read_object, 2017-06-21) without changing the corresponding return code. So let's do the minor cleanup of also changing this function to return a -1. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object-file.c b/object-file.c index 766ba88b851..8475b128944 100644 --- a/object-file.c +++ b/object-file.c @@ -1284,7 +1284,7 @@ int unpack_loose_header(git_zstream *stream, buffer, bufsiz); if (status < Z_OK) - return status; + return -1; /* Make sure we have the terminating NUL */ if (!memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer)) From patchwork Thu Sep 30 13:37:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F227C433F5 for ; Thu, 30 Sep 2021 13:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F12E1611C7 for ; Thu, 30 Sep 2021 13:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351718AbhI3Njj (ORCPT ); Thu, 30 Sep 2021 09:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351657AbhI3NjZ (ORCPT ); Thu, 30 Sep 2021 09:39:25 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB0CC061771 for ; Thu, 30 Sep 2021 06:37:38 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id u18so10134926wrg.5 for ; Thu, 30 Sep 2021 06:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bx73upVw5nERs8Wbb3A2jfMxeUw5sLzo19AD+T7vgb0=; b=NPKzHwOXRn8ZYinGDYWVXi1cMY/E/qX9pLy7xVHDJFPap+AKhvNS2Rz5WYacGJVgoe nk67rxXOasaWr1kW8gvxoGwjPf4HuokYZoWxHoxWzArefnQkB2FWGtbuWime0ZpzL0uB yL95UghCFGQaJRaZqinhFo/4vjft2LQ2i6l1PBLThm5cgUpragR9q87WgBXC0psfN+35 LJOTXs6Y4oLboTA+n/BfJIgYLXgC1VJS0OWvdYb3Fkocy253rI1/jGkzmxZ+w62pjKY2 6KZrU2rQxbAcxvS5WPPOVbI0YB3vJGqaCdKJi6dIYhO50c0V9HoG+Tni36eZua+EPoVY P3Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bx73upVw5nERs8Wbb3A2jfMxeUw5sLzo19AD+T7vgb0=; b=dxga9uGpw8MSAv79b6LD5bEIOH/YCMOsJwt1SW9RPFhpWAYKNgiLex7oDuUSbsjWks g1fpqcSneAdpJp6Q6Xpy64zet18MyT4PdmXhl06MakhFRjOcZuBfOn569QIeqotc2i/T wofv/hqXsh+8QkhlEo2RxS2uXFW9iGqD35SPLNenmwudiPryksJXlLuOsfIGebpzT6ND m9lJKcM38iPoyly1KnIYxzATOxD5Vx11gNrodCI282scKvFkMV1TGy239Wi5fI8S3d4c fL28TRyE5WkVm8hkohAssYKQCs1kwvJQwo0U79EOCM4mUEEiB6vN5hSdGq+14O2gA1y2 yWYw== X-Gm-Message-State: AOAM530SRpV0mktiHlu/JjK3kG7GdvU5YR7G+2pi/wJmnZyVoO7FSsAR cfBMCjmPOP6uwtMPc18uMitIlQKuDFmOquCQ X-Google-Smtp-Source: ABdhPJzH4CI842+uCiJ3vGW7iomPj6VGDbYzuGjWh7TMkIpK7CcsfP0BndWKWbzCQb1uWxxzn1YndQ== X-Received: by 2002:a5d:6dce:: with SMTP id d14mr6469350wrz.363.1633009057032; Thu, 30 Sep 2021 06:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 11/17] object-file.c: make parse_loose_header_extended() public Date: Thu, 30 Sep 2021 15:37:16 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make the parse_loose_header_extended() function public and remove the parse_loose_header() wrapper. The only direct user of it outside of object-file.c itself was in streaming.c, that caller can simply pass the required "struct object-info *" instead. This change is being done in preparation for teaching read_loose_object() to accept a flag to pass to parse_loose_header(). It isn't strictly necessary for that change, we could simply use parse_loose_header_extended() there, but will leave the API in a better end state. It would be a better end-state to have already moved the declaration of these functions to object-store.h to avoid the forward declaration of "struct object_info" in cache.h, but let's leave that cleanup for some other time. 1. https://lore.kernel.org/git/patch-v6-09.22-5b9278e7bb4-20210907T104559Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 4 +++- object-file.c | 20 +++++++------------- streaming.c | 5 ++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cache.h b/cache.h index f6295f3b048..35f254dae4a 100644 --- a/cache.h +++ b/cache.h @@ -1320,7 +1320,9 @@ char *xdg_cache_home(const char *filename); int git_open_cloexec(const char *name, int flags); #define git_open(name) git_open_cloexec(name, O_RDONLY) int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); -int parse_loose_header(const char *hdr, unsigned long *sizep); +struct object_info; +int parse_loose_header(const char *hdr, struct object_info *oi, + unsigned int flags); int check_object_signature(struct repository *r, const struct object_id *oid, void *buf, unsigned long size, const char *type); diff --git a/object-file.c b/object-file.c index 8475b128944..6b91c4edcf6 100644 --- a/object-file.c +++ b/object-file.c @@ -1385,8 +1385,8 @@ static void *unpack_loose_rest(git_zstream *stream, * too permissive for what we want to check. So do an anal * object header parse by hand. */ -static int parse_loose_header_extended(const char *hdr, struct object_info *oi, - unsigned int flags) +int parse_loose_header(const char *hdr, struct object_info *oi, + unsigned int flags) { const char *type_buf = hdr; unsigned long size; @@ -1446,14 +1446,6 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi, return *hdr ? -1 : type; } -int parse_loose_header(const char *hdr, unsigned long *sizep) -{ - struct object_info oi = OBJECT_INFO_INIT; - - oi.sizep = sizep; - return parse_loose_header_extended(hdr, &oi, 0); -} - static int loose_object_info(struct repository *r, const struct object_id *oid, struct object_info *oi, int flags) @@ -1508,10 +1500,10 @@ static int loose_object_info(struct repository *r, if (status < 0) ; /* Do nothing */ else if (hdrbuf.len) { - if ((status = parse_loose_header_extended(hdrbuf.buf, oi, flags)) < 0) + if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0) status = error(_("unable to parse %s header with --allow-unknown-type"), oid_to_hex(oid)); - } else if ((status = parse_loose_header_extended(hdr, oi, flags)) < 0) + } else if ((status = parse_loose_header(hdr, oi, flags)) < 0) status = error(_("unable to parse %s header"), oid_to_hex(oid)); if (status >= 0 && oi->contentp) { @@ -2599,6 +2591,8 @@ int read_loose_object(const char *path, unsigned long mapsize; git_zstream stream; char hdr[MAX_HEADER_LEN]; + struct object_info oi = OBJECT_INFO_INIT; + oi.sizep = size; *contents = NULL; @@ -2613,7 +2607,7 @@ int read_loose_object(const char *path, goto out; } - *type = parse_loose_header(hdr, size); + *type = parse_loose_header(hdr, &oi, 0); if (*type < 0) { error(_("unable to parse header of %s"), path); git_inflate_end(&stream); diff --git a/streaming.c b/streaming.c index 5f480ad50c4..8beac62cbb7 100644 --- a/streaming.c +++ b/streaming.c @@ -223,6 +223,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, const struct object_id *oid, enum object_type *type) { + struct object_info oi = OBJECT_INFO_INIT; + oi.sizep = &st->size; + st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize); if (!st->u.loose.mapped) return -1; @@ -231,7 +234,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, st->u.loose.mapsize, st->u.loose.hdr, sizeof(st->u.loose.hdr)) < 0) || - (parse_loose_header(st->u.loose.hdr, &st->size) < 0)) { + (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) { git_inflate_end(&st->z); munmap(st->u.loose.mapped, st->u.loose.mapsize); return -1; From patchwork Thu Sep 30 13:37:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 871B9C433EF for ; Thu, 30 Sep 2021 13:37:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F9DD611C7 for ; Thu, 30 Sep 2021 13:37:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351502AbhI3Njh (ORCPT ); Thu, 30 Sep 2021 09:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351656AbhI3NjZ (ORCPT ); Thu, 30 Sep 2021 09:39:25 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924F4C061773 for ; Thu, 30 Sep 2021 06:37:39 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id i23so10161254wrb.2 for ; Thu, 30 Sep 2021 06:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jADtJ3dhg2ojKhEz6bEsoX3ycrLX826AOaawl+abLRk=; b=njtvy/8+ns7PXIqhgDdWe930QI++5UnicHiUW3qLqZiNvBSZbAb+Y1xwB/bVp6lcYn mBCZrVDpQ78N3CJaZPtGY4ivORpBD0k16ET9s2S8BewS7rBhylcZ/vsgYHtN7KIrGgNI 5P1/NgqQjB2xImG32dZbQ8ykHQh7WA9wPil4athAoPNRaXqpR+UOfEU9x8BGhkHDnisi 2/XvqJvDFlRleE9kKNk+94NUSiUm4e46rjdicv27vNkuuEP1mK0q3Nu3krub//0aMkQ7 mEUJAq+KULMKqnza9HlyY8mQWCIUSjpgwUMpqFwabainiivfTAwZvVhg5DZQ29LPCjNs QPww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jADtJ3dhg2ojKhEz6bEsoX3ycrLX826AOaawl+abLRk=; b=Y/1DXZOdA2Im2EzV3O9vJoeAnuRxHj4Z4wMvjUBOTlP5aQJMPwYqTGiCcJI27QWxrP Vx8K6/YHwmCgUSNB47RYCX+SG9ILPO9ZsGfj5xqpgnLo8gJShOOdNR/vttwIxLKIRC1j lLwFfn5xeWHnFLy1ezbUgygMoQpfdb4+rAZohaFgGJNG3eMFoTwyXoDgzKSMMV8OrA88 9/guUTr+TTdu/JuHzja0fyRA1r1BAD9f3fsb6fcDNCt2zzqd4UqSr5eKXS3bRB+dG5Ch VVUGwka6I6mqqMNfrc8/2gYY806WcIY09rkc34IwhrQU++53/rfn1NJm1essiYP1WTol 1XSQ== X-Gm-Message-State: AOAM533GJkMc0de86l6dp81rYUI8YGL7caqPlgEDBQjwK9QocFyqmJMF oc5RwvH2EG9TUyJi0qWAfxkfSXqTFPMM4CKH X-Google-Smtp-Source: ABdhPJza/OXYEx/8XPGsFcajelz7Jpj4hkESsOGVHofuqvccjeciwGFVJGgg2rZZXyJVyV4aQ0eIPA== X-Received: by 2002:adf:e788:: with SMTP id n8mr6143991wrm.431.1633009057877; Thu, 30 Sep 2021 06:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 12/17] object-file.c: simplify unpack_loose_short_header() Date: Thu, 30 Sep 2021 15:37:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Combine the unpack_loose_short_header(), unpack_loose_header_to_strbuf() and unpack_loose_header() functions into one. The unpack_loose_header_to_strbuf() function was added in 46f034483eb (sha1_file: support reading from a loose object of unknown type, 2015-05-03). Its code was mostly copy/pasted between it and both of unpack_loose_header() and unpack_loose_short_header(). We now have a single unpack_loose_header() function which accepts an optional "struct strbuf *" instead. I think the remaining unpack_loose_header() function could be further simplified, we're carrying some complexity just to be able to emit a garbage type longer than MAX_HEADER_LEN, we could alternatively just say "we found a garbage type ..." instead. But let's leave the current behavior in place for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 17 ++++++++++++++- object-file.c | 58 ++++++++++++++++++--------------------------------- streaming.c | 3 ++- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/cache.h b/cache.h index 35f254dae4a..d7189aed8fc 100644 --- a/cache.h +++ b/cache.h @@ -1319,7 +1319,22 @@ char *xdg_cache_home(const char *filename); int git_open_cloexec(const char *name, int flags); #define git_open(name) git_open_cloexec(name, O_RDONLY) -int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); + +/** + * unpack_loose_header() initializes the data stream needed to unpack + * a loose object header. + * + * Returns 0 on success. Returns negative values on error. + * + * It will only parse up to MAX_HEADER_LEN bytes unless an optional + * "hdrbuf" argument is non-NULL. This is intended for use with + * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error) + * reporting. The full header will be extracted to "hdrbuf" for use + * with parse_loose_header(). + */ +int unpack_loose_header(git_zstream *stream, unsigned char *map, + unsigned long mapsize, void *buffer, + unsigned long bufsiz, struct strbuf *hdrbuf); struct object_info; int parse_loose_header(const char *hdr, struct object_info *oi, unsigned int flags); diff --git a/object-file.c b/object-file.c index 6b91c4edcf6..1327872cbf4 100644 --- a/object-file.c +++ b/object-file.c @@ -1255,11 +1255,12 @@ void *map_loose_object(struct repository *r, return map_loose_object_1(r, NULL, oid, size); } -static int unpack_loose_short_header(git_zstream *stream, - unsigned char *map, unsigned long mapsize, - void *buffer, unsigned long bufsiz) +int unpack_loose_header(git_zstream *stream, + unsigned char *map, unsigned long mapsize, + void *buffer, unsigned long bufsiz, + struct strbuf *header) { - int ret; + int status; /* Get the data stream */ memset(stream, 0, sizeof(*stream)); @@ -1270,35 +1271,8 @@ static int unpack_loose_short_header(git_zstream *stream, git_inflate_init(stream); obj_read_unlock(); - ret = git_inflate(stream, 0); + status = git_inflate(stream, 0); obj_read_lock(); - - return ret; -} - -int unpack_loose_header(git_zstream *stream, - unsigned char *map, unsigned long mapsize, - void *buffer, unsigned long bufsiz) -{ - int status = unpack_loose_short_header(stream, map, mapsize, - buffer, bufsiz); - - if (status < Z_OK) - return -1; - - /* Make sure we have the terminating NUL */ - if (!memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer)) - return -1; - return 0; -} - -static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map, - unsigned long mapsize, void *buffer, - unsigned long bufsiz, struct strbuf *header) -{ - int status; - - status = unpack_loose_short_header(stream, map, mapsize, buffer, bufsiz); if (status < Z_OK) return -1; @@ -1308,6 +1282,14 @@ static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer)) return 0; + /* + * We have a header longer than MAX_HEADER_LEN. The "header" + * here is only non-NULL when we run "cat-file + * --allow-unknown-type". + */ + if (!header) + return -1; + /* * buffer[0..bufsiz] was not large enough. Copy the partial * result out to header, and then append the result of further @@ -1457,6 +1439,7 @@ static int loose_object_info(struct repository *r, char hdr[MAX_HEADER_LEN]; struct strbuf hdrbuf = STRBUF_INIT; unsigned long size_scratch; + int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; if (oi->delta_base_oid) oidclr(oi->delta_base_oid); @@ -1490,11 +1473,9 @@ static int loose_object_info(struct repository *r, if (oi->disk_sizep) *oi->disk_sizep = mapsize; - if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) { - if (unpack_loose_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0) - status = error(_("unable to unpack %s header with --allow-unknown-type"), - oid_to_hex(oid)); - } else if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) + + if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), + allow_unknown ? &hdrbuf : NULL) < 0) status = error(_("unable to unpack %s header"), oid_to_hex(oid)); if (status < 0) @@ -2602,7 +2583,8 @@ int read_loose_object(const char *path, goto out; } - if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) { + if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), + NULL) < 0) { error(_("unable to unpack header of %s"), path); goto out; } diff --git a/streaming.c b/streaming.c index 8beac62cbb7..cb3c3cf6ff6 100644 --- a/streaming.c +++ b/streaming.c @@ -233,7 +233,8 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, st->u.loose.mapped, st->u.loose.mapsize, st->u.loose.hdr, - sizeof(st->u.loose.hdr)) < 0) || + sizeof(st->u.loose.hdr), + NULL) < 0) || (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) { git_inflate_end(&st->z); munmap(st->u.loose.mapped, st->u.loose.mapsize); From patchwork Thu Sep 30 13:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65DB7C433EF for ; Thu, 30 Sep 2021 13:38:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DA91611C7 for ; Thu, 30 Sep 2021 13:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351486AbhI3Njl (ORCPT ); Thu, 30 Sep 2021 09:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351661AbhI3Nj0 (ORCPT ); Thu, 30 Sep 2021 09:39:26 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC86C061775 for ; Thu, 30 Sep 2021 06:37:40 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id d6so10079587wrc.11 for ; Thu, 30 Sep 2021 06:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I/ufrHjsdVvWwigEmMNMHptrIhfYfXRz47MbA15bDpM=; b=AbmmktqQj3AsH3elVgyrfSC8lYl9Tq5YUAXAMNy/S0TKf5G3Objx/ckXzWCqeyuZuO XlWX6GHD7fCDEf8H6Mm1bZqoPX9R6sSZ3Iu6vHMos10Dft1z1ciBetYV/1RabgmePVVH nNArPUE9yr9T2798T1E1Hf9rcidtCZS4s0oBzzH5n3pbpRGyXIBO36b7KvZba0W4tTFA UPZtNIaQAF/gdktsNyWx1fE8KAofcanA5zqwRaANQyKFR82sE1nRDbE4tMycIgJJ9X1S jOr08BlxcOqyIeNFCQCKPwrD4h6OQD8lEPjjCmf3MgeurYbSwL9nduTmq0XdQMnsSXJ3 OlwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I/ufrHjsdVvWwigEmMNMHptrIhfYfXRz47MbA15bDpM=; b=klRI6HGe6r8TaFVjRqR39revba8bE1dGYeL3uEIdOX1rJuDNK0RTP1pz+VLGdWRMOU wtnHAgwxMYThNH3bgyWkWTvbkoinWOimuOAC3clABufTuZ2iXAB7PlebYEf86+APx9cZ uSj7amz8wO/dYATg47uxtsLwIyjBsZcJknUleuwFx79Ji/T4BO9XjwcBarBnRbPuEMIC MdV4kojF6yM1fRdVkvKixTmP5fiDE8p3nZUikmHOfaUofni2gI//W6U3Fz873YZF7cwV 1aLc5zLAp/hrCdbCcRDxwVBJSh0wELH5XblK8HErrZoBEEpq1Gqvr9vEmsqwEDVGew9/ Ex1A== X-Gm-Message-State: AOAM532UJivxl/dygyx13ENeijikHZmWxW+0quHwXDixZHV4GApQJr8i lVNU37fakI3dpguE70LWFSRZsblzk0f9vEXB X-Google-Smtp-Source: ABdhPJzT+WAyvANsN0+Y3fHQiJUXjlJ2dvnHKOZsKQX3djJKIaCLxiN7dQ/nrUyCopZCGELcKR4U0g== X-Received: by 2002:a05:6000:2c3:: with SMTP id o3mr6242306wry.76.1633009058921; Thu, 30 Sep 2021 06:37:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 13/17] object-file.c: use "enum" return type for unpack_loose_header() Date: Thu, 30 Sep 2021 15:37:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a preceding commit we changed and documented unpack_loose_header() from its previous behavior of returning any negative value or zero, to only -1 or 0. Let's add an "enum unpack_loose_header_result" type and use it for these return values, and have the compiler assert that we're exhaustively covering all of them. Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 19 +++++++++++++++---- object-file.c | 34 +++++++++++++++++++++------------- streaming.c | 23 +++++++++++++---------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/cache.h b/cache.h index d7189aed8fc..7239e20a625 100644 --- a/cache.h +++ b/cache.h @@ -1324,7 +1324,10 @@ int git_open_cloexec(const char *name, int flags); * unpack_loose_header() initializes the data stream needed to unpack * a loose object header. * - * Returns 0 on success. Returns negative values on error. + * Returns: + * + * - ULHR_OK on success + * - ULHR_BAD on error * * It will only parse up to MAX_HEADER_LEN bytes unless an optional * "hdrbuf" argument is non-NULL. This is intended for use with @@ -1332,9 +1335,17 @@ int git_open_cloexec(const char *name, int flags); * reporting. The full header will be extracted to "hdrbuf" for use * with parse_loose_header(). */ -int unpack_loose_header(git_zstream *stream, unsigned char *map, - unsigned long mapsize, void *buffer, - unsigned long bufsiz, struct strbuf *hdrbuf); +enum unpack_loose_header_result { + ULHR_OK, + ULHR_BAD, +}; +enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, + unsigned char *map, + unsigned long mapsize, + void *buffer, + unsigned long bufsiz, + struct strbuf *hdrbuf); + struct object_info; int parse_loose_header(const char *hdr, struct object_info *oi, unsigned int flags); diff --git a/object-file.c b/object-file.c index 1327872cbf4..e0f508415dd 100644 --- a/object-file.c +++ b/object-file.c @@ -1255,10 +1255,12 @@ void *map_loose_object(struct repository *r, return map_loose_object_1(r, NULL, oid, size); } -int unpack_loose_header(git_zstream *stream, - unsigned char *map, unsigned long mapsize, - void *buffer, unsigned long bufsiz, - struct strbuf *header) +enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, + unsigned char *map, + unsigned long mapsize, + void *buffer, + unsigned long bufsiz, + struct strbuf *header) { int status; @@ -1274,13 +1276,13 @@ int unpack_loose_header(git_zstream *stream, status = git_inflate(stream, 0); obj_read_lock(); if (status < Z_OK) - return -1; + return ULHR_BAD; /* * Check if entire header is unpacked in the first iteration. */ if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer)) - return 0; + return ULHR_OK; /* * We have a header longer than MAX_HEADER_LEN. The "header" @@ -1288,7 +1290,7 @@ int unpack_loose_header(git_zstream *stream, * --allow-unknown-type". */ if (!header) - return -1; + return ULHR_BAD; /* * buffer[0..bufsiz] was not large enough. Copy the partial @@ -1309,7 +1311,7 @@ int unpack_loose_header(git_zstream *stream, stream->next_out = buffer; stream->avail_out = bufsiz; } while (status != Z_STREAM_END); - return -1; + return ULHR_BAD; } static void *unpack_loose_rest(git_zstream *stream, @@ -1474,13 +1476,19 @@ static int loose_object_info(struct repository *r, if (oi->disk_sizep) *oi->disk_sizep = mapsize; - if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), - allow_unknown ? &hdrbuf : NULL) < 0) + switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), + allow_unknown ? &hdrbuf : NULL)) { + case ULHR_OK: + break; + case ULHR_BAD: status = error(_("unable to unpack %s header"), oid_to_hex(oid)); - if (status < 0) - ; /* Do nothing */ - else if (hdrbuf.len) { + break; + } + + if (status < 0) { + /* Do nothing */ + } else if (hdrbuf.len) { if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0) status = error(_("unable to parse %s header with --allow-unknown-type"), oid_to_hex(oid)); diff --git a/streaming.c b/streaming.c index cb3c3cf6ff6..6df0247a4cb 100644 --- a/streaming.c +++ b/streaming.c @@ -229,17 +229,16 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize); if (!st->u.loose.mapped) return -1; - if ((unpack_loose_header(&st->z, - st->u.loose.mapped, - st->u.loose.mapsize, - st->u.loose.hdr, - sizeof(st->u.loose.hdr), - NULL) < 0) || - (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) { - git_inflate_end(&st->z); - munmap(st->u.loose.mapped, st->u.loose.mapsize); - return -1; + switch (unpack_loose_header(&st->z, st->u.loose.mapped, + st->u.loose.mapsize, st->u.loose.hdr, + sizeof(st->u.loose.hdr), NULL)) { + case ULHR_OK: + break; + case ULHR_BAD: + goto error; } + if (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0) + goto error; st->u.loose.hdr_used = strlen(st->u.loose.hdr) + 1; st->u.loose.hdr_avail = st->z.total_out; @@ -248,6 +247,10 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, st->read = read_istream_loose; return 0; +error: + git_inflate_end(&st->z); + munmap(st->u.loose.mapped, st->u.loose.mapsize); + return -1; } From patchwork Thu Sep 30 13:37:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58AE0C433F5 for ; Thu, 30 Sep 2021 13:38:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40C8E6136A for ; Thu, 30 Sep 2021 13:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351723AbhI3Njm (ORCPT ); Thu, 30 Sep 2021 09:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351664AbhI3Nj0 (ORCPT ); Thu, 30 Sep 2021 09:39:26 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F8D4C061778 for ; Thu, 30 Sep 2021 06:37:41 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id u18so10135174wrg.5 for ; Thu, 30 Sep 2021 06:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WdZmlk6DZ/SPJTvYcYnzbFRIVLzQ8N/I9Ke9nqlyic4=; b=OhT4Bl2Urxu8szEiDajyuGs2X9A7Sh2xzgc72YP7z7lVO4+ASb9K+eDBiOVsNjCR+r rCHUkyCiAtjUhYT16Okc8x/kiN1zAXQCDzJvse3d7aCai8A2Ij3IH7/i/DzAFTrLOSfm /NdVJrnSexBkUnNXxZwkWEi4KspGVIh4Xhg7tTeR1CUZ/8oZFtrU0MvY1s0FeWRaZ9/+ /9gdbcVckUg1vWp9hbAQWjU0VFxTETch5V3+kYEBAqgnaykP5Ai2QWHoil/JzXjEHg25 Ce25DR4DoKKFSolo38n5UcnPF96xbF2DsYmE4zDMl7gSc9ytPVjnWROcK1j2UMfvJfz4 4zSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WdZmlk6DZ/SPJTvYcYnzbFRIVLzQ8N/I9Ke9nqlyic4=; b=zpSNAIiYf5oaU/9kQHRxCuJPl3NdE2zWGnIeLQTc0Hz9vQ9AfDOhCyDUt4DR8SI6qX 4Si1I6o6Q1Zdmirxesrp2jGMo4AfuwsNyuHT7Nu9Lphyc4ccOcA88ZME4OJuIJzUTSfW YC0LjyxMCV7x1pcnaAav4MsckWk3wqFYJnv8fXCstNZcyksOp5EJeJVf2Uu+TQkeNw9Y G+1OlGzty3rz3UGBgA43teggTEkMQE+W7sUlPrApYEss1D60tkrIipekFBND1bCsC+Bg DSmtS/36bLKwnFeyIunKHpr7prt1dwIHQpiAQ9BkXCy0xW2LgB1yhCmbKyKUapbBl9lb 2M9g== X-Gm-Message-State: AOAM532bcdFWrEYsnH+MiY5yFMuY2eHkNbABuViYi5mPXwAVOiyBdFJv bnloK9s7cH9ntCTvs+RlEZvbLlTsPVEPxTmq X-Google-Smtp-Source: ABdhPJw1Dxmuy1EJFxa8/YJ3Xna2BlJo8tJF0oBkcV2Ri5ynl7pFSrGe7+svgG8LZj71BrGXMVmSyQ== X-Received: by 2002:adf:f48d:: with SMTP id l13mr6136624wro.94.1633009059890; Thu, 30 Sep 2021 06:37:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 14/17] object-file.c: return ULHR_TOO_LONG on "header too long" Date: Thu, 30 Sep 2021 15:37:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split up the return code for "header too long" from the generic negative return value unpack_loose_header() returns, and report via error() if we exceed MAX_HEADER_LEN. As a test added earlier in this series in t1006-cat-file.sh shows we'll correctly emit zlib errors from zlib.c already in this case, so we have no need to carry those return codes further down the stack. Let's instead just return ULHR_TOO_LONG saying we ran into the MAX_HEADER_LEN limit, or other negative values for "unable to unpack header". Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 5 ++++- object-file.c | 8 ++++++-- streaming.c | 1 + t/t1006-cat-file.sh | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cache.h b/cache.h index 7239e20a625..8e05392fda8 100644 --- a/cache.h +++ b/cache.h @@ -1328,16 +1328,19 @@ int git_open_cloexec(const char *name, int flags); * * - ULHR_OK on success * - ULHR_BAD on error + * - ULHR_TOO_LONG if the header was too long * * It will only parse up to MAX_HEADER_LEN bytes unless an optional * "hdrbuf" argument is non-NULL. This is intended for use with * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error) * reporting. The full header will be extracted to "hdrbuf" for use - * with parse_loose_header(). + * with parse_loose_header(), ULHR_TOO_LONG will still be returned + * from this function to indicate that the header was too long. */ enum unpack_loose_header_result { ULHR_OK, ULHR_BAD, + ULHR_TOO_LONG, }; enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, unsigned char *map, diff --git a/object-file.c b/object-file.c index e0f508415dd..3589c5a2e33 100644 --- a/object-file.c +++ b/object-file.c @@ -1290,7 +1290,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, * --allow-unknown-type". */ if (!header) - return ULHR_BAD; + return ULHR_TOO_LONG; /* * buffer[0..bufsiz] was not large enough. Copy the partial @@ -1311,7 +1311,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, stream->next_out = buffer; stream->avail_out = bufsiz; } while (status != Z_STREAM_END); - return ULHR_BAD; + return ULHR_TOO_LONG; } static void *unpack_loose_rest(git_zstream *stream, @@ -1484,6 +1484,10 @@ static int loose_object_info(struct repository *r, status = error(_("unable to unpack %s header"), oid_to_hex(oid)); break; + case ULHR_TOO_LONG: + status = error(_("header for %s too long, exceeds %d bytes"), + oid_to_hex(oid), MAX_HEADER_LEN); + break; } if (status < 0) { diff --git a/streaming.c b/streaming.c index 6df0247a4cb..bd89c50e7b3 100644 --- a/streaming.c +++ b/streaming.c @@ -235,6 +235,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, case ULHR_OK: break; case ULHR_BAD: + case ULHR_TOO_LONG: goto error; } if (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 5b16c69c286..a5e7401af8b 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -356,12 +356,12 @@ do if test "$arg2" = "-p" then cat >expect <<-EOF - error: unable to unpack $bogus_long_sha1 header + error: header for $bogus_long_sha1 too long, exceeds 32 bytes fatal: Not a valid object name $bogus_long_sha1 EOF else cat >expect <<-EOF - error: unable to unpack $bogus_long_sha1 header + error: header for $bogus_long_sha1 too long, exceeds 32 bytes fatal: git cat-file: could not get object info EOF fi && From patchwork Thu Sep 30 13:37:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 841B2C433EF for ; Thu, 30 Sep 2021 13:38:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 681A1619E5 for ; Thu, 30 Sep 2021 13:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351647AbhI3Njp (ORCPT ); Thu, 30 Sep 2021 09:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351644AbhI3Nj1 (ORCPT ); Thu, 30 Sep 2021 09:39:27 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7489C06177B for ; Thu, 30 Sep 2021 06:37:42 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id i23so10161519wrb.2 for ; Thu, 30 Sep 2021 06:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oZcevelaL68hQw055V/kGuuBNP60uMDO+LAHPSDfDsU=; b=qIVgY+FLZJXlQ6wUy1S8WjjIMcyY3Ng2VWF1VDBUf1FAs2MYh4uSW/j9uWme//xIHd 1AtDKkzw5nTqAJboSMO7AxuuQPRZjx9fkeUdlnN0jIBqAgMiQhjbLyciljJh2k+58Za/ 8QncqhVZcKh9/FciUjC4NJinJQg5uKW8YcVgYEWhObd8cIqjPBlblogMBgjVaFkdhaqI MAlIA7vbP4yohEbHyn7TAbl7BWuky0dz2MZla06wOLwGBYDzjnCdygOoxncNogtYASit X44964XERwQbQakyjujnOjpC6RSixx0uN3JsRVnKdwxGv4Lg+r2CiVKP7YMP9gsu6fUG 8vGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oZcevelaL68hQw055V/kGuuBNP60uMDO+LAHPSDfDsU=; b=Ccdub4toDLRtHtNDZiP+dt1AgcE9TDVfmRV9efj9RUxDWDycwZ2BcvAUPg55Cywf9q fOD8zGELdv/dsoZcfOKTe8GAGtnmI3uWbXER+exeYw9xDVPVqQWiKt8ruIKYQUwhh88x MRTdavfVvYcobvgwv4xMXJ46kPdEyZAkrONJgf/dHzIaR5XU/z+QNiu5gRDzOOSVReyd 37iXbsm6i4ZAE9HwaUVsX+rnYR0JV3pgbZx9+mKFOOz3bYsOau6dcjG5XRvzSh8MdAEE vumLSFtvr8wCPz5aTG+Xd9AV79D2dE97D8pn+l5y5jXeqJBke6lmAjG4Oc4GJesqfmU/ 7Wvg== X-Gm-Message-State: AOAM533pQENWmU8pNj4eXfr9G1TZPSVgg9/bY8OyKqLeXya1I8qOpVua bsTJeqDRJwgjLgg123DL5mXJUSHlsMbSYmkC X-Google-Smtp-Source: ABdhPJxSafyv0AmXh7i6IhtrmwFWvsr9sAiu23bd7GRQ5Pc/qrJAFvYVp20+G8FnSgEZ82/Q8GauQg== X-Received: by 2002:a5d:64a7:: with SMTP id m7mr6349314wrp.171.1633009060782; Thu, 30 Sep 2021 06:37:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 15/17] object-file.c: stop dying in parse_loose_header() Date: Thu, 30 Sep 2021 15:37:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make parse_loose_header() return error codes and data instead of invoking die() by itself. For now we'll move the relevant die() call to loose_object_info() and read_loose_object() to keep this change smaller. In a subsequent commit we'll make read_loose_object() return an error code instead of dying. We should also address the "allow_unknown" case (should be moved to builtin/cat-file.c), but for now I'll be leaving it. For making parse_loose_header() not die() change its prototype to accept a "struct object_info *" instead of the "unsigned long *sizep" it accepted before. Its callers can now check the populated populated "oi->typep". Because of this we don't need to pass in the "unsigned int flags" which we used for OBJECT_INFO_ALLOW_UNKNOWN_TYPE, we can instead do that check in loose_object_info(). This also refactors some confusing control flow around the "status" variable. In some cases we set it to the return value of "error()", i.e. -1, and later checked if "status < 0" was true. Since 93cff9a978e (sha1_loose_object_info: return error for corrupted objects, 2017-04-01) the return value of loose_object_info() (then named sha1_loose_object_info()) had been a "status" variable that be any negative value, as we were expecting to return the "enum object_type". The only negative type happens to be OBJ_BAD, but the code still assumed that more might be added. This was then used later in e.g. c84a1f3ed4d (sha1_file: refactor read_object, 2017-06-21). Now that parse_loose_header() will return 0 on success instead of the type (which it'll stick into the "struct object_info") we don't need to conflate these two cases in its callers. Since parse_loose_header() doesn't need to return an arbitrary "status" we only need to treat its "ret < 0" specially, but can idiomatically overwrite it with our own error() return. This along with having made unpack_loose_header() return an "enum unpack_loose_header_result" in an earlier commit means that we can move the previously nested if/else cases mostly into the "ULHR_OK" branch of the "switch" statement. We should be less silent if we reach that "status = -1" branch, which happens if we've got trailing garbage in loose objects, see f6371f92104 (sha1_file: add read_loose_object() function, 2017-01-13) for a better way to handle it. For now let's punt on it, a subsequent commit will address that edge case. Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 11 +++++++-- object-file.c | 67 +++++++++++++++++++++++++-------------------------- streaming.c | 3 ++- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/cache.h b/cache.h index 8e05392fda8..6c5f00c82d5 100644 --- a/cache.h +++ b/cache.h @@ -1349,9 +1349,16 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, unsigned long bufsiz, struct strbuf *hdrbuf); +/** + * parse_loose_header() parses the starting " \0" of an + * object. If it doesn't follow that format -1 is returned. To check + * the validity of the populate the "typep" in the "struct + * object_info". It will be OBJ_BAD if the object type is unknown. The + * parsed can be retrieved via "oi->sizep", and from there + * passed to unpack_loose_rest(). + */ struct object_info; -int parse_loose_header(const char *hdr, struct object_info *oi, - unsigned int flags); +int parse_loose_header(const char *hdr, struct object_info *oi); int check_object_signature(struct repository *r, const struct object_id *oid, void *buf, unsigned long size, const char *type); diff --git a/object-file.c b/object-file.c index 3589c5a2e33..a70669700d0 100644 --- a/object-file.c +++ b/object-file.c @@ -1369,8 +1369,7 @@ static void *unpack_loose_rest(git_zstream *stream, * too permissive for what we want to check. So do an anal * object header parse by hand. */ -int parse_loose_header(const char *hdr, struct object_info *oi, - unsigned int flags) +int parse_loose_header(const char *hdr, struct object_info *oi) { const char *type_buf = hdr; unsigned long size; @@ -1392,15 +1391,6 @@ int parse_loose_header(const char *hdr, struct object_info *oi, type = type_from_string_gently(type_buf, type_len, 1); if (oi->type_name) strbuf_add(oi->type_name, type_buf, type_len); - /* - * Set type to 0 if its an unknown object and - * we're obtaining the type using '--allow-unknown-type' - * option. - */ - if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE) && (type < 0)) - type = 0; - else if (type < 0) - die(_("invalid object type")); if (oi->typep) *oi->typep = type; @@ -1427,7 +1417,14 @@ int parse_loose_header(const char *hdr, struct object_info *oi, /* * The length must be followed by a zero byte */ - return *hdr ? -1 : type; + if (*hdr) + return -1; + + /* + * The format is valid, but the type may still be bogus. The + * Caller needs to check its oi->typep. + */ + return 0; } static int loose_object_info(struct repository *r, @@ -1441,6 +1438,7 @@ static int loose_object_info(struct repository *r, char hdr[MAX_HEADER_LEN]; struct strbuf hdrbuf = STRBUF_INIT; unsigned long size_scratch; + enum object_type type_scratch; int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; if (oi->delta_base_oid) @@ -1472,6 +1470,8 @@ static int loose_object_info(struct repository *r, if (!oi->sizep) oi->sizep = &size_scratch; + if (!oi->typep) + oi->typep = &type_scratch; if (oi->disk_sizep) *oi->disk_sizep = mapsize; @@ -1479,6 +1479,18 @@ static int loose_object_info(struct repository *r, switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), allow_unknown ? &hdrbuf : NULL)) { case ULHR_OK: + if (parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi) < 0) + status = error(_("unable to parse %s header"), oid_to_hex(oid)); + else if (!allow_unknown && *oi->typep < 0) + die(_("invalid object type")); + + if (!oi->contentp) + break; + *oi->contentp = unpack_loose_rest(&stream, hdr, *oi->sizep, oid); + if (*oi->contentp) + goto cleanup; + + status = -1; break; case ULHR_BAD: status = error(_("unable to unpack %s header"), @@ -1490,31 +1502,16 @@ static int loose_object_info(struct repository *r, break; } - if (status < 0) { - /* Do nothing */ - } else if (hdrbuf.len) { - if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0) - status = error(_("unable to parse %s header with --allow-unknown-type"), - oid_to_hex(oid)); - } else if ((status = parse_loose_header(hdr, oi, flags)) < 0) - status = error(_("unable to parse %s header"), oid_to_hex(oid)); - - if (status >= 0 && oi->contentp) { - *oi->contentp = unpack_loose_rest(&stream, hdr, - *oi->sizep, oid); - if (!*oi->contentp) { - git_inflate_end(&stream); - status = -1; - } - } else - git_inflate_end(&stream); - + git_inflate_end(&stream); +cleanup: munmap(map, mapsize); if (oi->sizep == &size_scratch) oi->sizep = NULL; strbuf_release(&hdrbuf); + if (oi->typep == &type_scratch) + oi->typep = NULL; oi->whence = OI_LOOSE; - return (status < 0) ? status : 0; + return status; } int obj_read_use_lock = 0; @@ -2585,6 +2582,7 @@ int read_loose_object(const char *path, git_zstream stream; char hdr[MAX_HEADER_LEN]; struct object_info oi = OBJECT_INFO_INIT; + oi.typep = type; oi.sizep = size; *contents = NULL; @@ -2601,12 +2599,13 @@ int read_loose_object(const char *path, goto out; } - *type = parse_loose_header(hdr, &oi, 0); - if (*type < 0) { + if (parse_loose_header(hdr, &oi) < 0) { error(_("unable to parse header of %s"), path); git_inflate_end(&stream); goto out; } + if (*type < 0) + die(_("invalid object type")); if (*type == OBJ_BLOB && *size > big_file_threshold) { if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0) diff --git a/streaming.c b/streaming.c index bd89c50e7b3..fe54665d86e 100644 --- a/streaming.c +++ b/streaming.c @@ -225,6 +225,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, { struct object_info oi = OBJECT_INFO_INIT; oi.sizep = &st->size; + oi.typep = type; st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize); if (!st->u.loose.mapped) @@ -238,7 +239,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, case ULHR_TOO_LONG: goto error; } - if (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0) + if (parse_loose_header(st->u.loose.hdr, &oi) < 0 || *type < 0) goto error; st->u.loose.hdr_used = strlen(st->u.loose.hdr) + 1; From patchwork Thu Sep 30 13:37:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B44CC433FE for ; Thu, 30 Sep 2021 13:38:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2040C6136A for ; Thu, 30 Sep 2021 13:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351644AbhI3Njq (ORCPT ); Thu, 30 Sep 2021 09:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351676AbhI3Nj1 (ORCPT ); Thu, 30 Sep 2021 09:39:27 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5BDFC0613E4 for ; Thu, 30 Sep 2021 06:37:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u18so10135370wrg.5 for ; Thu, 30 Sep 2021 06:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=24ZpABOSqzF3qXtX1Tlaz3EGa+3Dtz7mj85LvmOEkvA=; b=FSADGTEScas0Cj/QwJz/YzL3cA8qJVLNm9NIWWnA+kq/vek7fUkWhV0f5GmTIqbxN9 GQN5JSD0YVqcuaFmT5x2rY3Wzt14mF9Rh8aPH7IwedIeGvLJxgTIFpVWcAEFbsOJdwlT xjSel1aM9QnD/xTvv8MJFXT+0I6Y1uivefXD+cbmZuPDI/3tUiLtJ4Bg+vBZbHTtUbtR B2qgHKWlZHKx2BXxgZR5nxZ41P+rv04nkbDLlWFg27KRCAjMZyyNL3DdE8WgKK99t/7h omsPu8PSTnlPaYGgm7bbTNC/DSNiAOyqVW7+r9494Jk7QWH2+1zcO8nnsdpvx8hoCf2p a7KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=24ZpABOSqzF3qXtX1Tlaz3EGa+3Dtz7mj85LvmOEkvA=; b=haOQ9Zx370ofzFqGTFKIAofvFtRKz/jwFQoYmYErfigGiXyEHDeSmnjC9pT7NtSiDV ZMXbERmqNJd+rb558ZIgSjkzMqK6AUizt7c45aI52arjY71Nil4L9gceIu3DteQV0D7I erFZRywGOHA+d4uIj7xT/jvbRj+6kPPzHvNisoR8RIAxVmBbllZ7MAWBDsbYn9moV8K/ hJQd+oG/lVudljl8gOlURnEqv2ZhJBy1odPxa2qDNog5rUBjdq1jyxAr8fPib2ctv9N8 007HK8edKGIobfJ5aqxYvr6gSbovqvgNpAHZDgEV2IKI5/EyfSv3JNw2ULYz8eDZcuTz 61FQ== X-Gm-Message-State: AOAM532NDX8pePdSRtRIVAurElPdDFYnVzd1LjIpAWLL1rJkDeukd2VY LY+C+I94/oElXOGXIfdtBPLezmftbgD7cpA0 X-Google-Smtp-Source: ABdhPJxuoaHHuA6PVN6H1+HgohXtH57MJnClSem+DQoikVg7UYejGwy9rEmGds/jJAbYl1DJy5MNkQ== X-Received: by 2002:adf:f44b:: with SMTP id f11mr6503774wrp.279.1633009061979; Thu, 30 Sep 2021 06:37:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 16/17] fsck: don't hard die on invalid object types Date: Thu, 30 Sep 2021 15:37:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the error fsck emits on invalid object types, such as: $ git hash-object --stdin -w -t garbage --literally From the very ungraceful error of: $ git fsck fatal: invalid object type $ To: $ git fsck error: : object is of unknown type 'garbage': [ other fsck output ] We'll still exit with non-zero, but now we'll finish the rest of the traversal. The tests that's being added here asserts that we'll still complain about other fsck issues (e.g. an unrelated dangling blob). To do this we need to pass down the "OBJECT_INFO_ALLOW_UNKNOWN_TYPE" flag from read_loose_object() through to parse_loose_header(). Since the read_loose_object() function is only used in builtin/fsck.c we can simply change it to accept a "struct object_info" (which contains the OBJECT_INFO_ALLOW_UNKNOWN_TYPE in its flags). See f6371f92104 (sha1_file: add read_loose_object() function, 2017-01-13) for the introduction of read_loose_object(). Since we're now passing in a "oi.type_name" we'll have to clean up the allocated "strbuf sb". That we're doing it right is asserted by e.g. the "fsck notices broken commit" test added in 03818a4a94c (split_ident: parse timestamp from end of line, 2013-10-14). To do that switch to a "goto cleanup" pattern, and while we're at it factor out the already duplicated free(content) to use that pattern. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 26 +++++++++++++++++++------- object-file.c | 18 ++++++------------ object-store.h | 6 +++--- t/t1450-fsck.sh | 17 +++++++++-------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index b42b6fe21f7..623f8fc3194 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -600,12 +600,23 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) unsigned long size; void *contents; int eaten; + struct strbuf sb = STRBUF_INIT; + struct object_info oi = OBJECT_INFO_INIT; + int err = 0; - if (read_loose_object(path, oid, &type, &size, &contents) < 0) { + oi.type_name = &sb; + oi.sizep = &size; + oi.typep = &type; + + if (read_loose_object(path, oid, &contents, &oi) < 0) + err = error(_("%s: object corrupt or missing: %s"), + oid_to_hex(oid), path); + if (type < 0) + err = error(_("%s: object is of unknown type '%s': %s"), + oid_to_hex(oid), sb.buf, path); + if (err) { errors_found |= ERROR_OBJECT; - error(_("%s: object corrupt or missing: %s"), - oid_to_hex(oid), path); - return 0; /* keep checking other objects */ + goto cleanup; } if (!contents && type != OBJ_BLOB) @@ -618,9 +629,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) errors_found |= ERROR_OBJECT; error(_("%s: object could not be parsed: %s"), oid_to_hex(oid), path); - if (!eaten) - free(contents); - return 0; /* keep checking other objects */ + goto cleanup_eaten; } obj->flags &= ~(REACHABLE | SEEN); @@ -628,8 +637,11 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) if (fsck_obj(obj, contents, size)) errors_found |= ERROR_OBJECT; +cleanup_eaten: if (!eaten) free(contents); +cleanup: + strbuf_release(&sb); return 0; /* keep checking other objects, even if we saw an error */ } diff --git a/object-file.c b/object-file.c index a70669700d0..fe95285f405 100644 --- a/object-file.c +++ b/object-file.c @@ -2572,18 +2572,15 @@ static int check_stream_oid(git_zstream *stream, int read_loose_object(const char *path, const struct object_id *expected_oid, - enum object_type *type, - unsigned long *size, - void **contents) + void **contents, + struct object_info *oi) { int ret = -1; void *map = NULL; unsigned long mapsize; git_zstream stream; char hdr[MAX_HEADER_LEN]; - struct object_info oi = OBJECT_INFO_INIT; - oi.typep = type; - oi.sizep = size; + unsigned long *size = oi->sizep; *contents = NULL; @@ -2599,15 +2596,13 @@ int read_loose_object(const char *path, goto out; } - if (parse_loose_header(hdr, &oi) < 0) { + if (parse_loose_header(hdr, oi) < 0) { error(_("unable to parse header of %s"), path); git_inflate_end(&stream); goto out; } - if (*type < 0) - die(_("invalid object type")); - if (*type == OBJ_BLOB && *size > big_file_threshold) { + if (*oi->typep == OBJ_BLOB && *size > big_file_threshold) { if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0) goto out; } else { @@ -2618,8 +2613,7 @@ int read_loose_object(const char *path, goto out; } if (check_object_signature(the_repository, expected_oid, - *contents, *size, - type_name(*type))) { + *contents, *size, oi->type_name->buf)) { error(_("hash mismatch for %s (expected %s)"), path, oid_to_hex(expected_oid)); free(*contents); diff --git a/object-store.h b/object-store.h index c5130d8baea..c90c41a07f7 100644 --- a/object-store.h +++ b/object-store.h @@ -245,6 +245,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime); /* * Open the loose object at path, check its hash, and return the contents, + * use the "oi" argument to assert things about the object, or e.g. populate its * type, and size. If the object is a blob, then "contents" may return NULL, * to allow streaming of large blobs. * @@ -252,9 +253,8 @@ int force_object_loose(const struct object_id *oid, time_t mtime); */ int read_loose_object(const char *path, const struct object_id *expected_oid, - enum object_type *type, - unsigned long *size, - void **contents); + void **contents, + struct object_info *oi); /* Retry packed storage after checking packed and loose storage */ #define HAS_OBJECT_RECHECK_PACKED 1 diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index bd696d21dba..167c319823a 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -85,11 +85,10 @@ test_expect_success 'object with hash and type mismatch' ' cmt=$(echo bogus | git commit-tree $tree) && git update-ref refs/heads/bogus $cmt && - cat >expect <<-\EOF && - fatal: invalid object type - EOF - test_must_fail git fsck 2>actual && - test_cmp expect actual + + test_must_fail git fsck 2>out && + grep "^error: hash mismatch for " out && + grep "^error: $oid: object is of unknown type '"'"'garbage'"'"'" out ) ' @@ -910,7 +909,7 @@ test_expect_success 'detect corrupt index file in fsck' ' test_i18ngrep "bad index file" errors ' -test_expect_success 'fsck hard errors on an invalid object type' ' +test_expect_success 'fsck error and recovery on invalid object type' ' git init --bare garbage-type && ( cd garbage-type && @@ -922,8 +921,10 @@ test_expect_success 'fsck hard errors on an invalid object type' ' fatal: invalid object type EOF test_must_fail git fsck >out 2>err && - test_cmp err.expect err && - test_must_be_empty out + grep -e "^error" -e "^fatal" err >errors && + test_line_count = 1 errors && + grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err && + grep "dangling blob $empty_blob" out ) ' From patchwork Thu Sep 30 13:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12528357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 474B8C433F5 for ; Thu, 30 Sep 2021 13:38:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B44C61211 for ; Thu, 30 Sep 2021 13:38:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351688AbhI3Nju (ORCPT ); Thu, 30 Sep 2021 09:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351677AbhI3Nj2 (ORCPT ); Thu, 30 Sep 2021 09:39:28 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B205DC06176A for ; Thu, 30 Sep 2021 06:37:44 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v17so10095394wrv.9 for ; Thu, 30 Sep 2021 06:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J1wyhHpBYgG5VOd2YKZRcn+26JraaPDCGdnBTCs9r5c=; b=okf0Yidmgl69fQpwr+16NnxvlIsSPlToTpjCD2Zw63I8BZhlQdF1OTjvZYXDZbI391 qsf11WyEpjt9cw+jDZCzx9Z6/PJVZSbHvvinLEifKlkTy/FATMg0sYdCkvS5VP4kjGce w0Ajq65CEsj5lHTJxsLb5Lpwo444a7VFbbn/WbbEyNpQ05O+exuxMxYNJ1Gan5BvIJM0 W6Zal9W5WX5+k/Kij7J/Lu73YSdCx6XBREk+m64oqCpR0/2reMnDKlc9x2vrkACUwt0A X8LqGF5qfsC82ABDrS5dklvtedUZqEn+1L0Cfm3HVNp85A75UVO/s/6qNBuCGiFL/8/n XGhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J1wyhHpBYgG5VOd2YKZRcn+26JraaPDCGdnBTCs9r5c=; b=nVZzEkns/pqT4TFzpvcr0cDJo/+P+gxLRung8VJjkd+q4Q5FDme7/R78e6o9ECqCF+ o/8tNHUqW0eivzdc9rM67oflCcAH+UmO3mGGWbKmMTHsQ/Lc/UCnA/jy/u6gCJHuEvT2 cm/hSHnbMfObWL2C+0uxo4c3vcefntDlRu2q9HuBuKy91iF0pL92pgZqw+ydOrsTRb9c Rve360jlHotRYHcTJPQt08lkv6t2AR+L1N4GFT/Xptc2XBNDeHDMyTWwFNoSqYjw8Glm xFwNZJngD7XJnIa+i/xbv70aysw6Z4Nn6ISgwSNyAtg5EC01n4s3kn6/dBviO653WNhS gn1Q== X-Gm-Message-State: AOAM532csMbUihZqHtP6BQHuyo3u4d1XjLmJc0wPYdvnDBaQwkOM3qrt JU9Nq5OtKiertFtdnMRsNXN1ROgNLJva5pht X-Google-Smtp-Source: ABdhPJzto+7LDxd0EGQ8cBoYe/YtwZvwzPDz1y8xt95kwNdPO3faI6qtaSU6MCFaC82wk/7C2NMT9A== X-Received: by 2002:a5d:59a4:: with SMTP id p4mr6018216wrr.332.1633009062883; Thu, 30 Sep 2021 06:37:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o11sm4654713wmh.11.2021.09.30.06.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 06:37:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v9 17/17] fsck: report invalid object type-path combinations Date: Thu, 30 Sep 2021 15:37:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1374.g05459a61530 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Improve the error that's emitted in cases where we find a loose object we parse, but which isn't at the location we expect it to be. Before this change we'd prefix the error with a not-a-OID derived from the path at which the object was found, due to an emergent behavior in how we'd end up with an "OID" in these codepaths. Now we'll instead say what object we hashed, and what path it was found at. Before this patch series e.g.: $ git hash-object --stdin -w -t blob >objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 $ git fsck error: garbage at end of loose object 'e69d[...]' error: unable to unpack contents of ./objects/e6/9d[...] error: e69d[...]: object corrupt or missing: ./objects/e6/9d[...] There is currently some weird messaging in the edge case when the two are combined, i.e. because we're not explicitly passing along an error state about this specific scenario from check_stream_oid() via read_loose_object() we'll end up printing the null OID if an object is of an unknown type *and* it can't be unpacked by zlib, e.g.: $ git hash-object --stdin -w -t garbage --literally >objects/83/15a83d2acc4c174aed59430f9a9c4ed926440f $ /usr/bin/git fsck fatal: invalid object type $ ~/g/git/git fsck error: garbage at end of loose object '8315a83d2acc4c174aed59430f9a9c4ed926440f' error: unable to unpack contents of ./objects/83/15a83d2acc4c174aed59430f9a9c4ed926440f error: 8315a83d2acc4c174aed59430f9a9c4ed926440f: object corrupt or missing: ./objects/83/15a83d2acc4c174aed59430f9a9c4ed926440f error: 0000000000000000000000000000000000000000: object is of unknown type 'garbage': ./objects/83/15a83d2acc4c174aed59430f9a9c4ed926440f [...] I think it's OK to leave that for future improvements, which would involve enum-ifying more error state as we've done with "enum unpack_loose_header_result" in preceding commits. In these increasingly more obscure cases the worst that can happen is that we'll get slightly nonsensical or inapplicable error messages. There's other such potential edge cases, all of which might produce some confusing messaging, but still be handled correctly as far as passing along errors goes. E.g. if check_object_signature() returns and oideq(real_oid, null_oid()) is true, which could happen if it returns -1 due to the read_istream() call having failed. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fast-export.c | 2 +- builtin/fsck.c | 23 +++++++++++++++-------- builtin/index-pack.c | 2 +- builtin/mktag.c | 3 ++- cache.h | 3 ++- object-file.c | 21 ++++++++++----------- object-store.h | 1 + object.c | 4 ++-- pack-check.c | 3 ++- t/t1006-cat-file.sh | 2 +- t/t1450-fsck.sh | 8 +++++--- 11 files changed, 42 insertions(+), 30 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 95e8e89e81f..8e2caf72819 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -312,7 +312,7 @@ static void export_blob(const struct object_id *oid) if (!buf) die("could not read blob %s", oid_to_hex(oid)); if (check_object_signature(the_repository, oid, buf, size, - type_name(type)) < 0) + type_name(type), NULL) < 0) die("oid mismatch in blob %s", oid_to_hex(oid)); object = parse_object_buffer(the_repository, oid, type, size, buf, &eaten); diff --git a/builtin/fsck.c b/builtin/fsck.c index 623f8fc3194..980c26e3b25 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -598,23 +598,30 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) struct object *obj; enum object_type type; unsigned long size; - void *contents; + unsigned char *contents = NULL; int eaten; struct strbuf sb = STRBUF_INIT; struct object_info oi = OBJECT_INFO_INIT; - int err = 0; + struct object_id real_oid = *null_oid(); + int ret; oi.type_name = &sb; oi.sizep = &size; oi.typep = &type; - if (read_loose_object(path, oid, &contents, &oi) < 0) - err = error(_("%s: object corrupt or missing: %s"), - oid_to_hex(oid), path); + ret = read_loose_object(path, oid, &real_oid, (void **)&contents, &oi); + if (ret < 0) { + if (contents && !oideq(&real_oid, oid)) + error(_("%s: hash-path mismatch, found at: %s"), + oid_to_hex(&real_oid), path); + else + error(_("%s: object corrupt or missing: %s"), + oid_to_hex(oid), path); + } if (type < 0) - err = error(_("%s: object is of unknown type '%s': %s"), - oid_to_hex(oid), sb.buf, path); - if (err) { + ret = error(_("%s: object is of unknown type '%s': %s"), + oid_to_hex(&real_oid), sb.buf, path); + if (ret < 0) { errors_found |= ERROR_OBJECT; goto cleanup; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 7ce69c087ec..15ae406e6b7 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1415,7 +1415,7 @@ static void fix_unresolved_deltas(struct hashfile *f) if (check_object_signature(the_repository, &d->oid, data, size, - type_name(type))) + type_name(type), NULL)) die(_("local object %s is corrupt"), oid_to_hex(&d->oid)); /* diff --git a/builtin/mktag.c b/builtin/mktag.c index dddcccdd368..3b2dbbb37e6 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -62,7 +62,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type) repl = lookup_replace_object(the_repository, tagged_oid); ret = check_object_signature(the_repository, repl, - buffer, size, type_name(*tagged_type)); + buffer, size, type_name(*tagged_type), + NULL); free(buffer); return ret; diff --git a/cache.h b/cache.h index 6c5f00c82d5..e2a203073ea 100644 --- a/cache.h +++ b/cache.h @@ -1361,7 +1361,8 @@ struct object_info; int parse_loose_header(const char *hdr, struct object_info *oi); int check_object_signature(struct repository *r, const struct object_id *oid, - void *buf, unsigned long size, const char *type); + void *buf, unsigned long size, const char *type, + struct object_id *real_oidp); int finalize_object_file(const char *tmpfile, const char *filename); diff --git a/object-file.c b/object-file.c index fe95285f405..49561e31551 100644 --- a/object-file.c +++ b/object-file.c @@ -1084,9 +1084,11 @@ void *xmmap(void *start, size_t length, * the streaming interface and rehash it to do the same. */ int check_object_signature(struct repository *r, const struct object_id *oid, - void *map, unsigned long size, const char *type) + void *map, unsigned long size, const char *type, + struct object_id *real_oidp) { - struct object_id real_oid; + struct object_id tmp; + struct object_id *real_oid = real_oidp ? real_oidp : &tmp; enum object_type obj_type; struct git_istream *st; git_hash_ctx c; @@ -1094,8 +1096,8 @@ int check_object_signature(struct repository *r, const struct object_id *oid, int hdrlen; if (map) { - hash_object_file(r->hash_algo, map, size, type, &real_oid); - return !oideq(oid, &real_oid) ? -1 : 0; + hash_object_file(r->hash_algo, map, size, type, real_oid); + return !oideq(oid, real_oid) ? -1 : 0; } st = open_istream(r, oid, &obj_type, &size, NULL); @@ -1120,9 +1122,9 @@ int check_object_signature(struct repository *r, const struct object_id *oid, break; r->hash_algo->update_fn(&c, buf, readlen); } - r->hash_algo->final_oid_fn(&real_oid, &c); + r->hash_algo->final_oid_fn(real_oid, &c); close_istream(st); - return !oideq(oid, &real_oid) ? -1 : 0; + return !oideq(oid, real_oid) ? -1 : 0; } int git_open_cloexec(const char *name, int flags) @@ -2572,6 +2574,7 @@ static int check_stream_oid(git_zstream *stream, int read_loose_object(const char *path, const struct object_id *expected_oid, + struct object_id *real_oid, void **contents, struct object_info *oi) { @@ -2582,8 +2585,6 @@ int read_loose_object(const char *path, char hdr[MAX_HEADER_LEN]; unsigned long *size = oi->sizep; - *contents = NULL; - map = map_loose_object_1(the_repository, path, NULL, &mapsize); if (!map) { error_errno(_("unable to mmap %s"), path); @@ -2613,9 +2614,7 @@ int read_loose_object(const char *path, goto out; } if (check_object_signature(the_repository, expected_oid, - *contents, *size, oi->type_name->buf)) { - error(_("hash mismatch for %s (expected %s)"), path, - oid_to_hex(expected_oid)); + *contents, *size, oi->type_name->buf, real_oid)) { free(*contents); goto out; } diff --git a/object-store.h b/object-store.h index c90c41a07f7..17b072e5a19 100644 --- a/object-store.h +++ b/object-store.h @@ -253,6 +253,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime); */ int read_loose_object(const char *path, const struct object_id *expected_oid, + struct object_id *real_oid, void **contents, struct object_info *oi); diff --git a/object.c b/object.c index 4e85955a941..23a24e678a8 100644 --- a/object.c +++ b/object.c @@ -279,7 +279,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) || (!obj && repo_has_object_file(r, oid) && oid_object_info(r, oid, NULL) == OBJ_BLOB)) { - if (check_object_signature(r, repl, NULL, 0, NULL) < 0) { + if (check_object_signature(r, repl, NULL, 0, NULL, NULL) < 0) { error(_("hash mismatch %s"), oid_to_hex(oid)); return NULL; } @@ -290,7 +290,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) buffer = repo_read_object_file(r, oid, &type, &size); if (buffer) { if (check_object_signature(r, repl, buffer, size, - type_name(type)) < 0) { + type_name(type), NULL) < 0) { free(buffer); error(_("hash mismatch %s"), oid_to_hex(repl)); return NULL; diff --git a/pack-check.c b/pack-check.c index c8e560d71ab..3f418e3a6af 100644 --- a/pack-check.c +++ b/pack-check.c @@ -142,7 +142,8 @@ static int verify_packfile(struct repository *r, err = error("cannot unpack %s from %s at offset %"PRIuMAX"", oid_to_hex(&oid), p->pack_name, (uintmax_t)entries[i].offset); - else if (check_object_signature(r, &oid, data, size, type_name(type))) + else if (check_object_signature(r, &oid, data, size, + type_name(type), NULL)) err = error("packed %s from %s is corrupt", oid_to_hex(&oid), p->pack_name); else if (fn) { diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index a5e7401af8b..0f52ca9cc82 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -512,7 +512,7 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' # Swap the two to corrupt the repository mv -f "$other_path" "$empty_path" && test_must_fail git fsck 2>err.fsck && - grep "hash mismatch" err.fsck && + grep "hash-path mismatch" err.fsck && # confirm that cat-file is reading the new swapped-in # blob... diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 167c319823a..eb0e772f098 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -54,6 +54,7 @@ test_expect_success 'object with hash mismatch' ' cd hash-mismatch && oid=$(echo blob | git hash-object -w --stdin) && + oldoid=$oid && old=$(test_oid_to_path "$oid") && new=$(dirname $old)/$(test_oid ff_2) && oid="$(dirname $new)$(basename $new)" && @@ -65,7 +66,7 @@ test_expect_success 'object with hash mismatch' ' git update-ref refs/heads/bogus $cmt && test_must_fail git fsck 2>out && - grep "$oid.*corrupt" out + grep "$oldoid: hash-path mismatch, found at: .*$new" out ) ' @@ -75,6 +76,7 @@ test_expect_success 'object with hash and type mismatch' ' cd hash-type-mismatch && oid=$(echo blob | git hash-object -w --stdin -t garbage --literally) && + oldoid=$oid && old=$(test_oid_to_path "$oid") && new=$(dirname $old)/$(test_oid ff_2) && oid="$(dirname $new)$(basename $new)" && @@ -87,8 +89,8 @@ test_expect_success 'object with hash and type mismatch' ' test_must_fail git fsck 2>out && - grep "^error: hash mismatch for " out && - grep "^error: $oid: object is of unknown type '"'"'garbage'"'"'" out + grep "^error: $oldoid: hash-path mismatch, found at: .*$new" out && + grep "^error: $oldoid: object is of unknown type '"'"'garbage'"'"'" out ) '