From patchwork Fri Oct 1 09:16:37 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: 12529909 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 024BAC433EF for ; Fri, 1 Oct 2021 09:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8D1861A51 for ; Fri, 1 Oct 2021 09:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352900AbhJAJSp (ORCPT ); Fri, 1 Oct 2021 05:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbhJAJSo (ORCPT ); Fri, 1 Oct 2021 05:18:44 -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 18DFEC061775 for ; Fri, 1 Oct 2021 02:17:00 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w29so14399700wra.8 for ; Fri, 01 Oct 2021 02:17:00 -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=RHaDeAFOWlryM+y8A4xm4T8eqObGfMQL7CAiFUpT13Y=; b=M6u+e1DIb5kL0LxveOhTBFp84bqc+sgn6hqcfjnxmNP2d3sytUZr1jaaP51ujHJcJk 6Qf5A+Xt/u8C8qqZHQs83h5ElnaNjMkSOkC694C0Kynkxaetj1Jt47tvlh8PmAAqpGEt 2zfXsKhDFu84F+RXfAHq4ruM74E3JNVFi44Tr+CPMK3iEjSxRqeIbxnf2c4q/MQ/KAA4 eMOElwaBpDsI7hhjvbRYEM8F2U7+TroxsAO6Mks0osmkYe4dx3CaAOgE0lSrMa/nH2FI uYj73E+krAo1G9muyc6ttg6JO1OHwTV5ldJ5X+3cNtztov6X4h9KvS1MVyqP9zywE7C1 jTDg== 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=RHaDeAFOWlryM+y8A4xm4T8eqObGfMQL7CAiFUpT13Y=; b=EBlvPn8o4dQkesc360ef/Ouao/fk4xdh9lcHbnMo1lYbc61kWMeF3nndKnatvJu+zR TG9CE8aqx2rTLmNRVNjsDBk7NOVC86JB9xWnBbJwt0lxXMfcrC68f1jJnCVToW2OtPyC L5jP6rsTuOYCmUfiFqS7klLAElWsoWJPAZO/CPqazSaVFDm6yoxxvhSEdqa3oQzTdcaN V9FM/GEBhwQpYuY9gSPfSQlouG/XsnTq5u57tWx9Pj3mqxrGpr/VBpuTKv53Aj5lUdmQ hOQEDM2TSzsPh4xFw8lNJak7k0GZw0tVHn/LtNW3ZHOmycOsvqzmrwKkYktc11EN729L A1uA== X-Gm-Message-State: AOAM532lchK/RM/P7qqrv2e+0OigHFXbKOrpz7OZehm+OLCbCuBjPKiF 0/Elqb1xttDVhAEcFS9PHHukMKvbAOc9tQ== X-Google-Smtp-Source: ABdhPJzR/2dxXHqwYONOulmXbA7oAA5itdPuWb+IbFUM9Sz89rAPJnqYBQ90uNfREr7KuR5v6/ro0g== X-Received: by 2002:a5d:63c6:: with SMTP id c6mr11228917wrw.186.1633079818395; Fri, 01 Oct 2021 02:16:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:16:57 -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 v10 01/17] fsck tests: add test for fsck-ing an unknown type Date: Fri, 1 Oct 2021 11:16:37 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 5071ac63a5b..beb233e91b1 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -865,4 +865,20 @@ 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 && + + git hash-object --stdin -w -t garbage --literally 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 Fri Oct 1 09:16:38 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: 12529911 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 6A7E3C433FE for ; Fri, 1 Oct 2021 09:17:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5234E6138F for ; Fri, 1 Oct 2021 09:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352910AbhJAJSq (ORCPT ); Fri, 1 Oct 2021 05:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352901AbhJAJSp (ORCPT ); Fri, 1 Oct 2021 05:18:45 -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 1089EC061775 for ; Fri, 1 Oct 2021 02:17:01 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d6so14331693wrc.11 for ; Fri, 01 Oct 2021 02:17:00 -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=mXLUjmlGKkd8yLNd8CNYUOG8cze97uHEPi0FyUyzwFA=; b=JvgGH8Zb+DcGs+62YDDfl2ebYVTuoQVXrC9NYYw28N7NFWXpyolPiwYev6Idlo4Voe a6hn641/YPiMh/cWBCzrbv5GJZk9ZYS4fFoVc8n3wNOe0JeiBdsVDnj0u9ZktgDVFLpH IEV+YqDxGNaNQTaWguuQbEJj4aUJSOGiwyzBQhCJ9BNRg/PZkpYO4+DjG76YrCrSfyV1 wUaAG293tF7H2OfQ9jmquh1sbmBQuMVUcNkWKuyz/3GyHuuVSFkDyhqEK32KJ1NPFO9s W3ZbyBSxGLkEidTu/VAlcc3AZi1pDvnq8gAhRtvj5ezdMnyWXKncYm2586nqYTjnog2T CKWg== 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=mXLUjmlGKkd8yLNd8CNYUOG8cze97uHEPi0FyUyzwFA=; b=1oXF8Si/tgc5pHJwIQZgqwMqBQzdnmQyI/cHTzJe2exv6u7YeCYMroZ70qAS6WaXU+ OQ48D22hJsIpOisuFBvx9KBIzOqwnVU+sI0WxtX4RI280+J0Jc0VflLXOduKOmCnXnRB dSeRQpliFjMywc2oOG0OciMMTIT3kyc2+NzzikUra/QoTufanJ5MiVLv3vbu8DWDoQD9 w7oDV1SDV2c7C3ILEJ7MoqN5hw2Gz7Z/TbZi9KmUDgEm5BrAn0XqF+gL2UrR6Gu4cwMR eZ8eZ6q9kR1/u9LtAx3GrmuVHuob0S5qQNEO5UYi6L5nfmxVeWdYTQsspjIf+GCgO8tq BavQ== X-Gm-Message-State: AOAM533kLjwl7vP/2kd5BQMy2FDf67tPAwFDtkNhnL89RTIJjbyKK9XG A55f/Gxl1fi2UFcpBQ0nJ0XsbiXfU5chmg== X-Google-Smtp-Source: ABdhPJzM166/sYySX2ilfXpCBio9r1T8M9Aob7G2EO6d25NLyHwMjIqEvxD3i3GIj7anpUOhHPhZ9A== X-Received: by 2002:a5d:64ee:: with SMTP id g14mr10875836wri.80.1633079819325; Fri, 01 Oct 2021 02:16:59 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:16:58 -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 v10 02/17] fsck tests: refactor one test to use a sub-repo Date: Fri, 1 Oct 2021 11:16:38 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 beb233e91b1..b73bc2a2ec3 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 Fri Oct 1 09:16:39 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: 12529913 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 2E04BC433EF for ; Fri, 1 Oct 2021 09:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13C1F61A81 for ; Fri, 1 Oct 2021 09:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352923AbhJAJSs (ORCPT ); Fri, 1 Oct 2021 05:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352909AbhJAJSp (ORCPT ); Fri, 1 Oct 2021 05:18:45 -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 D60C9C06177B for ; Fri, 1 Oct 2021 02:17:01 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v25so3781659wra.2 for ; Fri, 01 Oct 2021 02:17:01 -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=wL6wy4yENQiqFUkjAqTNTpNOV0/LP04Rh3m6j5j9Zzw=; b=UqAWkzGer5Ue69MPAaoQ/sdrJ/lNziv/0em3rFbgBDsAnCHRDGeBF3S6QZ6JngKC9z XO0ssu+ANILhQe8Qj4vSTi2vmgYCwGGXt1sw9zvFPANU+WyKxXWAUrdH42Xu43DHZT2q Ta7qh8L+O/ePSy84GUB7wm10wYxWigCV3N4CdE1UWzI5YR17jb9eiGcgwtFCw94sGfb5 NL0+mkJyoQeFJIgN/WMovPqPQRG7c0qgsa089H9Ax1VVBwYOOx4fR31rjwptlaJYKSVq s2n/XOXVRxCJIQO0KbmM0xlzY2eb8BYeEcBeFWTEWaY3pQH4z0BCLMXB4eUWwc/FuLi/ li6w== 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=wL6wy4yENQiqFUkjAqTNTpNOV0/LP04Rh3m6j5j9Zzw=; b=GTJUPJCtNgfu4kPq1059tmUBJrk7Shf3t5QSWvZMG/UxK/uqaGAW3zSg8kGsJ2Lb9Z dDIgQSEdHejuXwpn2qkgSoyvGGs9sioor0S5VWTJDV919/iv0a8dk2Tbza0hUcSngC7+ H35R9wXLqUnvpKcjYsNTZT1j+jj85tIUqCF6kDRA0A997LdNdQoSUgXxnUq05iD+L7Ub dYlUl339akF2g8DAl04b53QQ2OVNmPm1XLTmctihAaq4ytoMivsGe1EvGziaNVHXPEUd HPYOAQ6xSeLqcQv382bY8V+PPRo3dweG2B57NMW+khcaDI9diGCRZZoNjxvengeSUwUp Me0w== X-Gm-Message-State: AOAM533SKJM8LdF+uxx5zmyv0R4Udi/QoDpOZIU9NfGrvcnRcd2z+tpb hKqq8c2bBEAfZwzBqYlZwniEBE1i7U3ziA== X-Google-Smtp-Source: ABdhPJzr1q1X24yejUPJc40Taru/ajtlcUZjXTD5dh/Er7AsY5dvwBPsHkDiFgDWN/f4F6RCa6/VcQ== X-Received: by 2002:a5d:6da9:: with SMTP id u9mr11034294wrs.155.1633079820141; Fri, 01 Oct 2021 02:17:00 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:16:59 -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 v10 03/17] fsck tests: test current hash/type mismatch behavior Date: Fri, 1 Oct 2021 11:16:39 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 b73bc2a2ec3..f9cabcecd14 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 Fri Oct 1 09:16:40 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: 12529919 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 55FABC433EF for ; Fri, 1 Oct 2021 09:17:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38752610C8 for ; Fri, 1 Oct 2021 09:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352965AbhJAJS6 (ORCPT ); Fri, 1 Oct 2021 05:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352915AbhJAJSt (ORCPT ); Fri, 1 Oct 2021 05:18:49 -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 2B2D3C06177B for ; Fri, 1 Oct 2021 02:17:03 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id q17-20020a7bce91000000b0030d4e298215so730182wmj.0 for ; Fri, 01 Oct 2021 02:17:03 -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=u/kZVGaHdt9Pow4L0kVNsM0cKr+aE3rOPJbriFA3iqs=; b=UFK5yVz9tvKRAHEcbHsnZcpoK+24UfkeuOk+qHgDbmCqauPyMtb/A56HBl1nHYNJms enGAjtRYn+8kYIffsm60XGWdNimsb3TuOYQ3rFpvSn9PbxY311WSQkcfOtnTv2yVhDAU WDKRmgMwDqT34hc7V84m/BC2PspnonSOtGTdW8xgNRSdaMVMm7oWq7hWGJ/4W1pj2gz/ +hVTfpLyQvyujpZj/QqLWAYyagCeAEOR2jlL5tenw3R571dxjCtLD6jEJPiWDDKyhSon TW1ZxFtsvTI/uUGt8K1VQbsihcJ8zd+sQEWDltl/iKOknqWF6EA+n/lZgcza4RB4WaQr nZ3A== 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=u/kZVGaHdt9Pow4L0kVNsM0cKr+aE3rOPJbriFA3iqs=; b=oY/vy/HjXwIUiSW0D89437X5GQSDX+7thAz2434dqsxNToiYpxHAP4E4KmK9qES3Pb ofJ7p7xm078HUvUKDf4BEpirelAA8Q3tqXTAvKzzDtDRtbUR2X66yRS367pqx2UAYJSs aG+gIVo6Pug9Txg4Mg6ZOkwRNJ9iKSkYkN4xr6pzMK36UXVMmW1FFNjINclVFxtRtGdc Dexe1hFYt8vyGQuBDtOcSSp11pQyx0PEAYFAwwJTS3Hbzjq7EhchP3RUYgEhU4XZ2px4 g8AKgLtoxwk11tFCpAVNXtwDdy6ZXQlXuxBrQk5XD4FI4ceiONVBhjKvtWp4LiXEoRV1 uKrQ== X-Gm-Message-State: AOAM532FJzP8qPxpk72gUzaGoCO6a2RUrFocy4YSPdzBxXuQjL0CiFTb NpiwZValz56XJe69WmeyF3evIg8RSJzERw== X-Google-Smtp-Source: ABdhPJy2I7me500dZ6xCfWe43u9AqpbmBGUMkk7EeMFLVc2LXZh2o/jJ1wtEq1XPboB7sGmKSivpsA== X-Received: by 2002:a1c:f201:: with SMTP id s1mr3362907wmc.101.1633079821080; Fri, 01 Oct 2021 02:17:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:00 -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 v10 04/17] fsck tests: test for garbage appended to a loose object Date: Fri, 1 Oct 2021 11:16:40 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 f9cabcecd14..281ff8bdd8e 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 Fri Oct 1 09:16:41 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: 12529915 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 B13B9C433EF for ; Fri, 1 Oct 2021 09:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AA8261A05 for ; Fri, 1 Oct 2021 09:17:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352873AbhJAJS4 (ORCPT ); Fri, 1 Oct 2021 05:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352918AbhJAJSt (ORCPT ); Fri, 1 Oct 2021 05:18:49 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADA24C06177D for ; Fri, 1 Oct 2021 02:17:03 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m14-20020a05600c3b0e00b0030d4dffd04fso955088wms.3 for ; Fri, 01 Oct 2021 02:17:03 -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=71yTilJ2DAeNlCYObfyVNUHcZ9Bkfy3rE0g6g38iEgY=; b=EnfYhaA5ulHnwKyUpg/MS+RImd6uhaWBiQQC87UpipnyjyQP67y7obxD7w4MMO09PS omQBTgpJyUO6OoI2b4scQSXwPrilD504Vwe9G4UYDmC0XM3QRkdTxfGTWIr8ANewkvq+ m4ouVypDxgHJ62NUOOuYWSgEgY3+jbrwfqPuE0PKWP8WgpXCo7hgDcYmYZRp09yEUcvv mMiZc9JtajJfxuQsIC3A4VS4ES3mjeEXrD853UhWYcxaRPjiibdvT/menxrVVklLAv3m 4o9JrZYdbYgrKWkwjWEEBwf+2IiEZXfSZfZt+8qJ1SHmQpNyIF2xqGfd+aFrn/BeUarS jr3A== 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=71yTilJ2DAeNlCYObfyVNUHcZ9Bkfy3rE0g6g38iEgY=; b=xYwyQayvhUvsmHdY2UaSZdRkYE8CozMwmVuIJVn/n8znk9UwaJg9Lk/yIiLEYB7trT NjAPg4ESDHJeSE1IGdquF5jnxWTsXuTlBJKuqNI3W7+BbcEXHY2LeC1Grkz+wVGtsOsy xeZyEHicwvBYOVhp5axJSij2xLBuhe6WjORQi9Du/TRfC6kBLQSzvZjqTB86E/EnCHPe j3eU4OjOncE+vdyPSpLNAHY+nlYvJhl+OzZ16vDZ/sg/27JDSx92aspzj4YkNEMEjv5B g97CISUhz84USgmPPThG5/0GMl79vEHfc6guykVWqAoLjqWzLDmeLhnNDSZTPS2XY8TK WnfQ== X-Gm-Message-State: AOAM531uKj2Y6QrSluYg9FRowzurJQVkpj3ksN+qfGNXWb4OclS441K3 +Txp3+Me0SxvlCMOJenDFFAHpj15S4aV3Q== X-Google-Smtp-Source: ABdhPJxq3rrE/sydya9mlvIEMqewm3fbYzp9u3vxwdEEYF6826Ea51rg2W9BZWz00KRPw/2VK68Oxg== X-Received: by 2002:a1c:3b86:: with SMTP id i128mr3360349wma.132.1633079821877; Fri, 01 Oct 2021 02:17:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:01 -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 v10 05/17] cat-file tests: move bogus_* variable declarations earlier Date: Fri, 1 Oct 2021 11:16:41 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:42 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: 12529917 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 BC67FC433F5 for ; Fri, 1 Oct 2021 09:17:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0845610C8 for ; Fri, 1 Oct 2021 09:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352935AbhJAJS5 (ORCPT ); Fri, 1 Oct 2021 05:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352909AbhJAJSv (ORCPT ); Fri, 1 Oct 2021 05:18:51 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCEC8C0613E2 for ; Fri, 1 Oct 2021 02:17:04 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id j27so6740359wms.0 for ; Fri, 01 Oct 2021 02:17:04 -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=T7v8TdyQ32Cu9JcLQY3VyGyq9zySMfN56Hxa7Ls+Ras=; b=YYeuw2foAJK3jjSS/je0QNCNNvoaXzJob7UfQRFR7kDmtUS8h21Wha1Lpr2dsE6fg2 /HmkMyp7B7S5MWcb77zrqXJrQrxZjbgTPlHGJAbtwH0NvUr4cf1GK17FJvZGJemEVShD 0QAgM8iC6GS1splVNguh1RX0R3gp0Hdv2D3nkXQAJVpZyjHdBs4yY+G42J8LaxwKTRZV 1MnA1wfFNJmKcRXX4SHoqU8E8NoACiMHxRyR2X3j0Nq1r6W6S3V8a2fHJ6JQVUdYUsUC B3JeqwfOq4Bg6QpkFZ8guUlcPY6X9dCxOgfwx3j+kMV8zO77xabyNzZcH9KowGWRR7NJ 2xzA== 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=T7v8TdyQ32Cu9JcLQY3VyGyq9zySMfN56Hxa7Ls+Ras=; b=hBYjTSBscEfIk50OvCbtmmymEDiJTjgVql0Cy5rkp/SMXYukQoXkycSU20qTFVEVAw G4rs16g5Y458ri5/vIuD13Lb1rd9Kv8+Z46oArjV1eDDnQ1cg1VlDdqhOua4qzm7mPeV EGbxUWT4N0uqqMgKo3D9cij6t3FfRA0YsE3W3YlkhWklgvXHBqnrPJgCoDfo3rXmdkfQ mMTsS+mCCkSvkavVD1pIKM5A+bjf0zDis4AHbLxe2zjXfxjPHxjCYnmKUOU0XyNO29se YktyAB6TNsHOEXOGMZyLA64+OO4ygBXgANiHXL7exq3HpAHk1T/Jg/cARGBi3+CCaGJy TGEQ== X-Gm-Message-State: AOAM530AvutqFnSFBrucrvS1buIr4LtOa1qZhlzLGw5ImtQeo0M5cL7R x91Me+YAjZSQeXI0Jam8axI0jwKoxqrItg== X-Google-Smtp-Source: ABdhPJxCSCIiAp/k3PCSPHCFEuAJWQpqzPkA7YkXISPwUNdga4hN1N/gwMLI+EMEsOrJO0FuyIR8YA== X-Received: by 2002:a1c:98d1:: with SMTP id a200mr3412308wme.86.1633079823039; Fri, 01 Oct 2021 02:17:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:02 -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 v10 06/17] cat-file tests: test for missing/bogus object with -t, -s and -p Date: Fri, 1 Oct 2021 11:16:42 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:43 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: 12529921 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 29CA7C433F5 for ; Fri, 1 Oct 2021 09:17:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16ACF61A51 for ; Fri, 1 Oct 2021 09:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352977AbhJAJTA (ORCPT ); Fri, 1 Oct 2021 05:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352933AbhJAJSx (ORCPT ); Fri, 1 Oct 2021 05:18:53 -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 AAB4AC0613E3 for ; Fri, 1 Oct 2021 02:17:05 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id d21so14360847wra.12 for ; Fri, 01 Oct 2021 02:17:05 -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=WEWMcm9Fm7re5QjzYF2qR6MKXh+iIxFBhMI785xe9mw=; b=DrVgSHo2uig4IKpZo6Zr2VuLeXCyiwfCJLo7dzEx9Ln4Bxf5i/E7JXnDkwOD99NEE+ xeDa82OubY53HgfKnvnQsNMAm0nzqKXoG4rdlr6RZS6Rg/fvPKXSPOLiRixwZHSkwX3Q iSx2HH5ny0NevJdXKHnF+5GYPfu58rnUBaO3SYk61AZOt79hW3L5FEAX4cQKEox0y4mx 6OHA/FWHKsLZqtzYZxOCSL8VbEG43O5mWAYNu605GyrSIdKy064wHPy9Smy27k0mZ+CB Ea5mYJ5Kt/Lp2WMzUs6nJRLEHqV1y1u4PFQZpcCIykHup77UlPtTY4U9IoQjpa7pQ0DY uRLA== 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=WEWMcm9Fm7re5QjzYF2qR6MKXh+iIxFBhMI785xe9mw=; b=MWKq9q8brJRUrywnMqiCxIMkCX6BttHOzuNaWe5gkft5OvYHeEuUjGwvEiUAJT/LF5 btCZYM2Q8OLGpIEtK2dMWX8PLgKV1jEpgQwseYZsUAMGNUU6oSvYne/4lCSNexsFVSgd L+Yfecxryolk65mkLJv6lXcwxCC2Rw6VaRlhFL74JNEjoZXkzdw+P9BKo1JHemoSgTbZ Dsvqcrs/MQU14D2HmICH1neNZV3++41nLmbI26Lr1LxaofBaKFBGVogWPrJZ3QnXBnUo heo5QQaHvEsA7JsMMHcLAb3uZuzWOHfhB7tdDTLSWYf5vXDg+lJr8+EYGXr8buLTGLpi BQ6Q== X-Gm-Message-State: AOAM531r/sotZHl2vvDLVTsbGj5fzGSwvgppCdYpnt0TLYGVfHEVta1C pEJlwGt7FGU4bDrxoIyZLA780Htul/eleg== X-Google-Smtp-Source: ABdhPJwObBFQmwBQCQfQbobnpXkVSEJfEmXCdp+gOeuH7o2VCPrr7wMKciKUwyDzVvx2IB0DrCI/7g== X-Received: by 2002:a5d:6506:: with SMTP id x6mr11141258wru.255.1633079824021; Fri, 01 Oct 2021 02:17:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:03 -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 v10 07/17] cat-file tests: add corrupt loose object test Date: Fri, 1 Oct 2021 11:16:43 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:44 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: 12529923 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 2512CC433FE for ; Fri, 1 Oct 2021 09:17:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C613610C8 for ; Fri, 1 Oct 2021 09:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352983AbhJAJTA (ORCPT ); Fri, 1 Oct 2021 05:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352938AbhJAJSy (ORCPT ); Fri, 1 Oct 2021 05:18:54 -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 A509CC0613E7 for ; Fri, 1 Oct 2021 02:17:06 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id h15so12776068wrc.3 for ; Fri, 01 Oct 2021 02:17:06 -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=WqMH4XHQj4B7JL5zu9YTFHI2EyOWDLmUkqdSOlcTwc8=; b=XUWU/z8oKooEu5Nt/F0SkJo9wC+RYDAA5sc/f8sV1ZOt+b840c8ZmqZyj3TeS5h+N9 9na/EQcnL5nPO/BF7+hKAvEojSN0DJMYxvoqh4e5eoH/W6sZq28WNU/NTLbIzImKDafJ Pf8EuGlLvfxrF5xx/KxDO8Ln0bcs5uexVCSvor7i0XEELzVBw5nF6BaHDF9/SQgvowI6 u44c0zrImVifJB/2kreJpRU6Fv7ZAQYjnijRLV5s432TJWObeEmVTbPdAzqDWQktGQCu zCK5RZiMVu8B6lp3Z8OKhXmShd+R7cddTHtRLFOQz1s7MeVhUeN3B6h3C1J2stieQJWa pFAA== 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=WqMH4XHQj4B7JL5zu9YTFHI2EyOWDLmUkqdSOlcTwc8=; b=i6BY34TmeoGSdvbHP3GYYaGcpF1jXcTT1QofuFzcSAueAv3e1HVKVb1Zf+NqSfCZ99 AaXsFU3nPlKNYkLcgxG4HQdGU6ePRZTQZf9ZyyiFoHdG1kQyvnEYPCgdf5kUhuYu2M/r 3H/pq9LYug7oExIA87aqUzGp5Km0AQP8OwMMT9JXV6q71CTCWrW+uSVaFG2luo9dU8Ey aX9xJ5Ulo4kD0qNtOG1ZTK2WMkznLvc7eZxhFCyPjTOSgwXPHxjkbq2daAT6ixVJQuNo o6gQ2Q2vYs79C7cYM4J8S4wGEweLo1B3eTnJbHIXuFsamPCDZqUP8jz3dvOtIP839g0G bUYQ== X-Gm-Message-State: AOAM531I8q55bkuxpA9JRzu6r0pxGbmzIrywWw553J73JDcdfRQsAUkl aeT/twS+Lk32mkFjGCtInUykAYdvz1nsdQ== X-Google-Smtp-Source: ABdhPJxLDNywO/rrcuKEgBCaRCZFcHwCywp32Ke/167ucQw2sJlpF4wg9fxIeT/Ry+SyjHnDtkEzYA== X-Received: by 2002:a5d:47ad:: with SMTP id 13mr11282273wrb.77.1633079824955; Fri, 01 Oct 2021 02:17:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:04 -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 v10 08/17] cat-file tests: test for current --allow-unknown-type behavior Date: Fri, 1 Oct 2021 11:16:44 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:45 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: 12529925 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 5807AC4332F for ; Fri, 1 Oct 2021 09:17:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CFA061A81 for ; Fri, 1 Oct 2021 09:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352989AbhJAJTC (ORCPT ); Fri, 1 Oct 2021 05:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352944AbhJAJSy (ORCPT ); Fri, 1 Oct 2021 05:18:54 -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 8269DC0613EE for ; Fri, 1 Oct 2021 02:17:07 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id m14-20020a05600c3b0e00b0030d4dffd04fso955205wms.3 for ; Fri, 01 Oct 2021 02:17:07 -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=yGq+Fn5V7JiiyfwcgQoial0GWCkXEXr+dmufABdvoos=; b=LWhugktxJLCoONLZvJ0E7OutrMAWccAED3TFIeEjZ/NWlxUKeBXlyPUhilnoKmB/8F 8hxB0i+wc8N6xCxjgK3Za7gxrrDmNfvDov9Ec6aw/7Lc56GV6bA4cKGik96EQL5OVsFu M36hsK6bdoCywOM7T7xrG9efj2pSHlmeQMnmc0j+coCsHzslHIYGum1Ibp2nPEW1rFYZ gVanap3CZD6Y/ayRn/fQIQbkzusrxy8FbLZYo9+jx/TobJB6qh2Jy2kkQoKLoc16XpGc 42I3h8QnlT9VVufdPjtk+pVyD27Qe+Wobt0wMZ1b7rjhvq1V4sS9LHY0VET1Smt9bb4n 4Q7A== 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=yGq+Fn5V7JiiyfwcgQoial0GWCkXEXr+dmufABdvoos=; b=KugEese++/PgzAAmy86L+XwS6vbbl4LLSbniuklokwMVrGi2Qz0lU/8StKa9Fmh+MU Ep7Iq4PJC7sbY49gFbEsbFg6qWpl0T6b1+FxV0th4gc+vTGVIkflE/p2LIiMaW5BqGt9 aqPuNrKLTZ/2zGp8BbIbB2Uoj4rK9l29QAqZVmzyAJl3IEuntGDunki3pujw4UGXvuI1 9QdwTOdLEITHKZBD9sfPtNC53ogXdF3Iy0HaC6R2JxYvX1r7AHk9JHXucG3W3CSA3Pu1 dpfgZkCiWfY6JoD/hmkYKnqaWrSFrLL0Ae2uCZksvZY5XjFD99zD5fO4NFGJv1jE0Or1 as9w== X-Gm-Message-State: AOAM533Ga/L3zk6HsMaVQLUW7UkMshOXMQrjBMmlTBxHwo0+JtZBXUcz VSUVUprZPVpWb/5VzdWi5QX1q6mzySgU1Q== X-Google-Smtp-Source: ABdhPJwrB1epjMZ7cmUoocsjyWOfxZ6YHFukQQNQAGviyKkEJsLxRlnMVnzL+cutkHiw1xfbQtzAoQ== X-Received: by 2002:a1c:7508:: with SMTP id o8mr3433010wmc.104.1633079825771; Fri, 01 Oct 2021 02:17:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:05 -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 v10 09/17] object-file.c: don't set "typep" when returning non-zero Date: Fri, 1 Oct 2021 11:16:45 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:46 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: 12529927 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 710FCC433F5 for ; Fri, 1 Oct 2021 09:17:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50AB7610C8 for ; Fri, 1 Oct 2021 09:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352991AbhJAJTC (ORCPT ); Fri, 1 Oct 2021 05:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352922AbhJAJSy (ORCPT ); Fri, 1 Oct 2021 05:18:54 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7999BC061775 for ; Fri, 1 Oct 2021 02:17:08 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id z184-20020a1c7ec1000000b003065f0bc631so10711252wmc.0 for ; Fri, 01 Oct 2021 02:17:08 -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=0LtpOaAYEhc9+JHygSA2ZAw6tjmkIcZsS5TdyGk2V58=; b=fd09JrXtESqwAZujT5B/cSXLyzqldRubZYrXqkVEOwmXJ4QCelUulxNAKlUpvBHI0W 1OLdMfpFE51lYWbMhinKVtd08oC98Y2nZyS8Wpjry07xt3kPOJ+5Vh9FTPku24FRkljC fKmk8nBi76clhLMFWeee/A8p3QNQOp0pVn6DwX/fzMW+V9lc1ItdKIs0GcQs50TQXP5S ImaYAqpkj4oQntmEBV6PKYBbMXrVTEkgF+cQ4/cK7HHe2Uu6IUJ6oVKA6A82zTxzA+9M ZHyoF5RuXDmPw7KINTOoof0suEILCV/Kd8PwxEjylB1y4Ep/FUp25/XOno73P48ZjNZL rliA== 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=0LtpOaAYEhc9+JHygSA2ZAw6tjmkIcZsS5TdyGk2V58=; b=HEV747uelj64bwirB8IsQx3BJjOJyvuwWVmxZgfFCLv3oZlvCxPiOLAD9jqzZtnd8e PY3wSW+ShF38c3A54wqJ6gEnd+R0lOEqW02DrTCPMEK+NTaGhnbJDQlb3dXtMzQvHAuQ kbzlTrz6oxefNab/Q/Vk1T9RuUXU/YoY3bh7dKWFiNnHcmDwd3x0h7NQ4kyer/ZIVaH8 wOvx8BRKzC+yU7vNgYhNU5AGrPPetS6fMTB6cwoQ5hcFaQ9JPs9lDgadJrwQPIWO0jvp V2F/HPmlIu071cj/W9LVUPcDIZPDcHfVSQYnHAbH64It0uVVUe2WAkVEh4GPM+mKK7lL t9uw== X-Gm-Message-State: AOAM530LyYj3F9Ban0/LhiScpioXIbpM9KLOImC+G3707n7Gj1xMsYcS RnfDZDxBarIsSlyD5qrZtfJFsJ2DizH+Bg== X-Google-Smtp-Source: ABdhPJxFwwE9/ZUxJ1r/D5UJX1KeEGg8zAC8i71LMEfczpQ4eofkfu7z2+psghqjO21WS04CLVNpqw== X-Received: by 2002:a05:600c:4f42:: with SMTP id m2mr3242396wmq.151.1633079826748; Fri, 01 Oct 2021 02:17:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:06 -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 v10 10/17] object-file.c: return -1, not "status" from unpack_loose_header() Date: Fri, 1 Oct 2021 11:16:46 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:47 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: 12529929 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 DB28AC433F5 for ; Fri, 1 Oct 2021 09:17:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5FB661A05 for ; Fri, 1 Oct 2021 09:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352996AbhJAJTF (ORCPT ); Fri, 1 Oct 2021 05:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352948AbhJAJSy (ORCPT ); Fri, 1 Oct 2021 05:18:54 -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 6A3A2C061780 for ; Fri, 1 Oct 2021 02:17:09 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id s21so14365265wra.7 for ; Fri, 01 Oct 2021 02:17:09 -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=vAjUOKextceGLVm1fBAHGNpuxKbDs0FdbuIeENw5//s=; b=VvQLXm3tat39rBQl3tVU13Yo0glBrySokoyIMbgkBobAeeMGIakca7nIFayv4Am9Rv QpbDX19y6mqf6UEDe5BbpRCDWJeKgpTFsJXQbHW24h5fSJAmhKnoZDJhkSp6vRCeLUDZ u5f04PWDYAh7ei8hkinEjc7U+H7onZzEk1Wm0ntVavZx88WoVJ8vpe/pTWMrL6Vx/Ric Fsxtz5JVDJ16xVqnzP4+ouOzippcS34ap6W6GohEuLIYaf2HtlOpCv26xamnxWfmeEyo 8ymAYwaMP20Fs9CgpUaWaLRHhX0+ikMCllLowxc1gcNXUd7EJLKWoF1esBBPwqAyUESO oHlQ== 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=vAjUOKextceGLVm1fBAHGNpuxKbDs0FdbuIeENw5//s=; b=5nbxiZLCCAj3CoHHJC3OQwslYFfJ/fZLoadVr57zsBbOsoBYaMRfdlhiKfSdL9GnrM ll6FASK7Q73CnAMzta2p7wzIigfbYGwIAEHV/JWlSFKpSfotHCfMvOKBfGBXQs2Ywppb 4r84z46Osi4fYiZ44Qm1vStSrK+vVeqbNrfmZLBTO/vhym7JiH/sETJP+GR6PB1KEEKg EaBUc9+a2HeCOc5qS1I29SiBq5oNSFCQfhXg2XIrzpSJoRXKBMfWJaQoSnIt2JCGVKBN dRtnGbkdEG8Y3Hn0NBy9l8Es7UQjgM2tPOUcenHd5oo3aOPA3Yj5Nf9Di70CmmudcFaV T7FQ== X-Gm-Message-State: AOAM530NSdl9l4M4eZXvYpjrlXqeljxJlxI0NjtJ/RNW7uRLt+xFgmK0 4ET5WDwm5jSusOTKro6/IAekIfxMC1eUxg== X-Google-Smtp-Source: ABdhPJweQnklt1lxaibD6eCJ+3itv6ItqkKU/Wp73TaXhaTYUQ1l3z9szN8NgTElPYYcUouNx5i5oQ== X-Received: by 2002:adf:a101:: with SMTP id o1mr10724670wro.379.1633079827723; Fri, 01 Oct 2021 02:17:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:07 -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 v10 11/17] object-file.c: make parse_loose_header_extended() public Date: Fri, 1 Oct 2021 11:16:47 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:48 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: 12529931 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 ABB91C433EF for ; Fri, 1 Oct 2021 09:17:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8948561A05 for ; Fri, 1 Oct 2021 09:17:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353035AbhJAJTK (ORCPT ); Fri, 1 Oct 2021 05:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352921AbhJAJS4 (ORCPT ); Fri, 1 Oct 2021 05:18:56 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C89AC06177C for ; Fri, 1 Oct 2021 02:17:10 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j27so6740566wms.0 for ; Fri, 01 Oct 2021 02:17:10 -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=Ttv4dIG30ar8Kt3+MCn1I8ZwjPd/tGVday0iMQncQLg=; b=KjeX/jThyAWXIwX7/zeMBI8B/x090PWPxm92TeFqHSXcOIT6Vs67yqzupjjHQWrkKs ifIWP2ckG6Y+vJU+eHQN+g9QfkKWgeRZ6ysnEBKjsXuBjZw70yzQsUBVWm3M8QUiPpqM Ef242WU9XZ8PMILgHbum7CdS75lRc+HvkLaVOoaUuZa6mfSFaClLoabL0O6u9CPU8BCD hNEUx6Wenw7uSFvsH+fSvEMK8dzUrNmQhDYhpcZaNKJr9zIxLQHC7jO4GYaddan8sl6t Ffi2yN1LAEEuGJ15o1eqcMtCAEWJrv2OzgdQJw2hl8Tlp3kcts3lKwuGUW9uuhq5SSGm kGWA== 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=Ttv4dIG30ar8Kt3+MCn1I8ZwjPd/tGVday0iMQncQLg=; b=cUu93m7um0ibCGmrATv6l+5DfLD6dKvPcwOsu2x5riqwmKUiHC9KoR48ejvNLNV35/ mmsbI/JOXj9iPoExO4rVG3UzmYpsrb5HR/b9oU2Ip7WBPo48++t43+10TOD0aDXVZpwf bQSJ0BVr2vEYRhUfTWqrl6fu900nhpZHVagNa39V5gkBH+3AlBcDNMu6PHiQR8HgIkrH 3CJSJdBCsNadftPmx0Xjb5X9ldOeWY2fhNzuUltTyJevxOP9y5mxxgdCnWwOBw76l1QI W2ygrffn0/o5KGzZn4fxSxkn80DZhiic9vCoznc7SoRLSfeAZL3spuAxeCJydmXL1/9d wJgg== X-Gm-Message-State: AOAM532x/UV3ymFM54Dfa5sXE5oUvOhIJFmR0ogjv0TKpjHxaYwaZOzN EMdaut7ut0NykhBWWWZd79NVrxJvmPVoeA== X-Google-Smtp-Source: ABdhPJwBBXCoW0RYRpwbsrJkeVxVUwVUPdQ5lHnzWLqXAWhczfTSpWOVA+AEYTPs5PelgAaRQwQKZA== X-Received: by 2002:a05:600c:4ca2:: with SMTP id g34mr3298840wmp.193.1633079828560; Fri, 01 Oct 2021 02:17:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:07 -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 v10 12/17] object-file.c: simplify unpack_loose_short_header() Date: Fri, 1 Oct 2021 11:16:48 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:49 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: 12529933 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 40322C433EF for ; Fri, 1 Oct 2021 09:17:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 204AD610C8 for ; Fri, 1 Oct 2021 09:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353039AbhJAJTN (ORCPT ); Fri, 1 Oct 2021 05:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352957AbhJAJS4 (ORCPT ); Fri, 1 Oct 2021 05:18:56 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 390AEC0613E2 for ; Fri, 1 Oct 2021 02:17:11 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id d207-20020a1c1dd8000000b00307e2d1ec1aso6250900wmd.5 for ; Fri, 01 Oct 2021 02:17:11 -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=BqZP66xUi2OuZk5vJ5x1is+EPUtJn78Tjml2wJJ1F1E=; b=mttrqhfNRt6m4f0inC+Q4dIWDHUWMEYXF8cbFeQtGdCSgjEoLW1LDtE0l3Ce2YrT+3 V8FmhE/Db/4uaBZF9Hcmls1z0P6SFOwi9Y4+ap26PvR81KBrUEomRUHLMDG0U+E5dmQq I2uos379ZLK+noOi0C1ajG+J2AN/Mo87Frd8vA/hE+AmRN0aZGCnHVdqyJyLW8NOF9bH lMungI1Nv90KYgKukTJRvDnuZrtRL+YyxdADl1Un205N23b1iF5UqALRwN8tqQuNOaTK wmGG6aV14aTGJvOJowC2JQcCKR9Dz9o9M2gGtvXtOVuFy7/XeUDYZmyCVGeaDGJYR9u/ fPxg== 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=BqZP66xUi2OuZk5vJ5x1is+EPUtJn78Tjml2wJJ1F1E=; b=wEi928RYQ/GYQ6yN6XMSg9geYFLiUZWBlPhUdudg7ANNact86hVwg3VuvswUuv/Fkk SQslgozBgP6Z3sQP4u7FDCZ0wQNrtSUbiYiS8dgM7MNIeDELpyOz1xaGUG7BvsThZbFl ZS4m1PMkEO51lG/zZrIgr4JhsND5zMWJtEsOGXnNn4IV5qV3vGEt2NvN7sznIb5rENBr EjQtBbvFpZmmSRpGk2oaTzym7zSz/S/PJMGUivqFF2VxLokwtDbUHNAuVBu3YMPZEJ5A koIUMgAjjQGMvRlxJj4R2zVR0uFHj3WnYOtCEIpIg7G86fKG1agqo7fntfqskw9xwb3+ XhGw== X-Gm-Message-State: AOAM533qFqYACEruyYRsRYs6kseHHmu4qnKtVIi+GxCVc27Gay2LlqCN g8mzB0jdJV29BI9Zc5PpTI0RHXxYeBa/YQ== X-Google-Smtp-Source: ABdhPJyEeXe/5jLgkMwFOA1rAm2mQ49/RMj1hF2HHWlNRQNUdWQReaND+WSDxWIprHsl3dO14CPc4Q== X-Received: by 2002:a05:600c:4fd2:: with SMTP id o18mr3318299wmq.126.1633079829549; Fri, 01 Oct 2021 02:17:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:08 -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 v10 13/17] object-file.c: use "enum" return type for unpack_loose_header() Date: Fri, 1 Oct 2021 11:16:49 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:50 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: 12529935 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 0A6A5C433F5 for ; Fri, 1 Oct 2021 09:17:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E31EB610C8 for ; Fri, 1 Oct 2021 09:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353044AbhJAJTR (ORCPT ); Fri, 1 Oct 2021 05:19:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352931AbhJAJS4 (ORCPT ); Fri, 1 Oct 2021 05:18:56 -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 14506C061786 for ; Fri, 1 Oct 2021 02:17:12 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id v17so14363565wrv.9 for ; Fri, 01 Oct 2021 02:17:12 -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=ZwVH2SgugwjEGByJercspBC18AoKSgWL44xy11kLnpI=; b=MjhBcRhRiDrIWX/iYAm3JyjYkjWhx2O4KPktG4aNEmKn4s/yjt11yV9RkyEb19JL0n 8dajgRcXTQ4uSc2ZTPXWgjJryIiqGAwGl36fRiXJY/5Cez/6zcVYt9f8Gg5RhZFfqRxv 46f5Q+5B5hHZd6JYP5MBvZe/E40NjWQSAXM2LzOhc7x4BZuZ1s/xy4mq3Qa95HoIjjXR Su92e1hhyfljlhmDFAmMXGdjJutxpOqih0CFdh58jwgVDkFSbTtBIxPUYeEV0jSIPMuX fZFpEkFzQCfp60bf8kIcdTlM+a8lPTN6pWf9uV/NzdpheCsDIg+JeOH0HphUaJD3a0lv LhUA== 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=ZwVH2SgugwjEGByJercspBC18AoKSgWL44xy11kLnpI=; b=PdtYNkiOFwDpM1Zu98ZynivX8fqztbTQpVFJhqm0b4vSEKOdvr0UAvlO2/174YTL48 jRDuRgzQS6TUBJ6u+8a+CQae5obxQPsUIIYcwm1jIuTOB/zu2Y1rwWwShTvB4YdJ8X2s IVU8flE5vsWE6TfGd8LzsB3hdMizPX/6K9vVM8n0T4XbgLvHQUSUKQoXyKQBZ6hWjp80 n65y7iBNgOjj/Y9tUcNhyMVO7nK58bnygNt7C+Zv+gVaLyhvCqTNFvrrfV9q7WUb3FGm dNzwMeWqILaMxPS8jcUbqxPkYVVHPVYg+lcL5MHjvqrWETYJRJy30xFOf9lwQCRIychP x4Lw== X-Gm-Message-State: AOAM531hnSlrY9cFHFuefBmYggEBbicXk+8JkjNIsBGVnanVcbFJYSZs rIyUQSASoklBUwy6IeY1fEFhKkKzEAYGRQ== X-Google-Smtp-Source: ABdhPJwka7zbgiBn0xFvOPk1UhYpEsp8bDxbwKcSUwtOsN1wiA8LyZL73uqR+Eo4pd9ZDoFdNzmDwQ== X-Received: by 2002:adf:8b45:: with SMTP id v5mr11161802wra.211.1633079830350; Fri, 01 Oct 2021 02:17:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:09 -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 v10 14/17] object-file.c: return ULHR_TOO_LONG on "header too long" Date: Fri, 1 Oct 2021 11:16:50 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:51 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: 12529937 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 62C7DC433FE for ; Fri, 1 Oct 2021 09:17:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FBBE610C8 for ; Fri, 1 Oct 2021 09:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353055AbhJAJTT (ORCPT ); Fri, 1 Oct 2021 05:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352968AbhJAJS5 (ORCPT ); Fri, 1 Oct 2021 05:18:57 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C8E7C0613E3 for ; Fri, 1 Oct 2021 02:17:13 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id d207-20020a1c1dd8000000b00307e2d1ec1aso6250965wmd.5 for ; Fri, 01 Oct 2021 02:17:12 -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=IiS4H0Kz8FWhByxf+okWWP11VbclNbQErhkd9iP6l5o=; b=GUyfbu3HXNEKjAyuYv5T/mjFyUd+UlIh8COFk5rnc+wDWlbqxzoBxRovoDN5KtKzvx Wob1zQC5Z7IHbj82g8C9seeoZLWPd63jUjEhp9gvb9/enIhzSI2zurEFXzboSeOdkc9q odDFqdimskT0hZcZPTAv1/f/urRFzFn10BxqACiWzx6Q4Il5IX3BbTY8KmQPSXfNvpSR ElZ9EgGJkrNvrHyPQiWYrj7dhUMQa2GbGO7NEi9TasvsdOKME5aHl3EgtLyqTRZowt/b zyLWRVvUSH/mU068LAevl7zSaxWZfdTfZq0m92T5m+Euz0WBTU+MQ7p5s2HQnmRWccME VMow== 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=IiS4H0Kz8FWhByxf+okWWP11VbclNbQErhkd9iP6l5o=; b=qQkwNcXQDo87BMrS5gDBiGFV+wAMV1jkUJIRhjdvzOAHWbLiqhCyr7mxoIWgj+P8S/ vxpB4ngo4eA+0dECz2GFYHIMLVikHOFvxMgKvYRyHBRBA1iU6TiFW7Dl0DQiSLaeERJU Pzd9RWfppUaeJjS0aBqMyKaEEv9jzryTwUENEXkVdRe9k923Ad6jNKXNOQoXQXHsn1t4 026HudiLrvgKW2Zn/R9KbQlWtK8mDayHGGl0ctLyTWM7xyX1sd3Xw6qEb4+frW9LGndP 81Bum6nHPOoEWJOaTpbHhgcE4lofxyPDPlMhVIYkR//xIqTZHw9AHfidkO3TPjrU54zd hL4A== X-Gm-Message-State: AOAM530C4ul4Y315xyiTMeAUeR/2c6jIxchlyVrKzHQWL3ffypQNttDV Dt4tSK4bTHygcVqd+gMr8DgggELcswUahA== X-Google-Smtp-Source: ABdhPJyYcV99VI+K/CKtFBz1HM83cw2NAn7IEBS+4U6I5BOXNFfzo6vk3gyDOBof1/wUjeBwax5dzg== X-Received: by 2002:a1c:98d1:: with SMTP id a200mr3412896wme.86.1633079831171; Fri, 01 Oct 2021 02:17:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:10 -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 v10 15/17] object-file.c: stop dying in parse_loose_header() Date: Fri, 1 Oct 2021 11:16:51 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 Fri Oct 1 09:16:52 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: 12529939 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 AE254C433F5 for ; Fri, 1 Oct 2021 09:17:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 938DE61A51 for ; Fri, 1 Oct 2021 09:17:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352945AbhJAJTU (ORCPT ); Fri, 1 Oct 2021 05:19:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352939AbhJAJS6 (ORCPT ); Fri, 1 Oct 2021 05:18:58 -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 01925C0613E6 for ; Fri, 1 Oct 2021 02:17:14 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v25so3782537wra.2 for ; Fri, 01 Oct 2021 02:17:13 -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=wxlNVP/mZQHw4yS0Kse8QeakZcyuqxu4Ldvsu7oML4M=; b=QjOIQdLzrB0awR350yJyJ+ggEzQJlC/KQ6l5G8dfxiorQF5ljruO/t3skDNHL2bKiz IX4uynaunhuUo5TQmkkEtrPI/I5PUGgpI8PvMBeoQMMQZlyiLPjuMDn1KFptJ+L5xCN0 7ovtU1blyzHQJxGeOdbgO5zGks2/okLmGBhu7WYlBHgbXQ9ji8VMdwkc//zwhZErXsKn A06dmuSm5YlS55eBovGgSiAv622AgGnPS02S0e3hd/tDhU3IeuMfivLiZtltuStXZxyl QSv7zhntCsKV2iWpfN4FRKQ+M6ezGQtEfw8MBcYUT4oMgQJpqrG3r6fAhebYdU+l08zW dpzw== 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=wxlNVP/mZQHw4yS0Kse8QeakZcyuqxu4Ldvsu7oML4M=; b=o8A48e4udAJxoSOfBWIYdmynI2ht5JVgQcU0zGkKbSN1ThpyTQ0w6gRhodtigj9obQ xOfDqs2mkmkwsB/QkVj8FPGsBOC61Cn5kOl1JaOJo0ntYyG4/WCEIc6V7+c1KWJQ1VPs Kf72pAU5MGxBE6Ps0BIJUBTa/fciNfFujNslBb3cSkxzAd3UTgPSeS17XjfUTbFZxaV1 ua12D6bn0qUw7rQ0LQ/Az7QSKeX6CiJkM6+UcNd1mBsdj/z6F5Ci3QlFNMh3KDT3nhLF 9BjKQ5axGGAKnblRxHM8rII4e9/KZzGpMWVohhjJNdCOL4wgSoY9iy3pXz9Fb0h7BoGR 1DqQ== X-Gm-Message-State: AOAM530mjy1895yLRreR3CWslhUWpnodsMB12HVW59ivsVmNMUXsYpza x6PUsbzZlZOGHlbWRryV0JDJk5UDjqnn3Q== X-Google-Smtp-Source: ABdhPJzY3COfzGWXpa5pDocM+2ZPAiGmhhsuY/OhX4qGleLCPGa0hDB5YiXFLbIyjf/NYGSmGW6L5Q== X-Received: by 2002:adf:b355:: with SMTP id k21mr2039818wrd.380.1633079832243; Fri, 01 Oct 2021 02:17:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:11 -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 v10 16/17] fsck: don't hard die on invalid object types Date: Fri, 1 Oct 2021 11:16:52 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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'll need a "struct strbuf" to hold the "type_name" let's pass it to the for_each_loose_file_in_objdir() callback to avoid allocating a new one for each loose object in the iteration. It also makes the memory management simpler than sticking it in fsck_loose() itself, as we'll only need to strbuf_reset() it, with no need to do a strbuf_release() before each "return". Before this commit we'd never check the "type" if read_loose_object() failed, but now we do. We therefore need to initialize it to OBJ_NONE to be able to tell the difference between e.g. its unpack_loose_header() having failed, and us getting past that and into parse_loose_header(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 37 +++++++++++++++++++++++++++++++------ object-file.c | 18 ++++++------------ object-store.h | 6 +++--- t/t1450-fsck.sh | 18 +++++++++--------- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index b42b6fe21f7..260210bf8a1 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -593,18 +593,36 @@ static void get_default_heads(void) } } +struct for_each_loose_cb +{ + struct progress *progress; + struct strbuf obj_type; +}; + static int fsck_loose(const struct object_id *oid, const char *path, void *data) { + struct for_each_loose_cb *cb_data = data; struct object *obj; - enum object_type type; + enum object_type type = OBJ_NONE; unsigned long size; void *contents; int eaten; + struct object_info oi = OBJECT_INFO_INIT; + int err = 0; - if (read_loose_object(path, oid, &type, &size, &contents) < 0) { + strbuf_reset(&cb_data->obj_type); + oi.type_name = &cb_data->obj_type; + 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 != OBJ_NONE && type < 0) + err = error(_("%s: object is of unknown type '%s': %s"), + oid_to_hex(oid), cb_data->obj_type.buf, path); + if (err < 0) { errors_found |= ERROR_OBJECT; - error(_("%s: object corrupt or missing: %s"), - oid_to_hex(oid), path); return 0; /* keep checking other objects */ } @@ -640,8 +658,10 @@ static int fsck_cruft(const char *basename, const char *path, void *data) return 0; } -static int fsck_subdir(unsigned int nr, const char *path, void *progress) +static int fsck_subdir(unsigned int nr, const char *path, void *data) { + struct for_each_loose_cb *cb_data = data; + struct progress *progress = cb_data->progress; display_progress(progress, nr + 1); return 0; } @@ -649,6 +669,10 @@ static int fsck_subdir(unsigned int nr, const char *path, void *progress) static void fsck_object_dir(const char *path) { struct progress *progress = NULL; + struct for_each_loose_cb cb_data = { + .obj_type = STRBUF_INIT, + .progress = progress, + }; if (verbose) fprintf_ln(stderr, _("Checking object directory")); @@ -657,9 +681,10 @@ static void fsck_object_dir(const char *path) progress = start_progress(_("Checking object directories"), 256); for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir, - progress); + &cb_data); display_progress(progress, 256); stop_progress(&progress); + strbuf_release(&cb_data.obj_type); } static int fsck_head_link(const char *head_ref_name, 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 281ff8bdd8e..faf0e98847b 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,19 +909,20 @@ 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 && - git hash-object --stdin -w -t garbage --literally 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 + grep -e "^error" -e "^fatal" err >errors && + test_line_count = 1 errors && + grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err ) ' From patchwork Fri Oct 1 09:16:53 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: 12529941 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 C25DAC433F5 for ; Fri, 1 Oct 2021 09:17:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A733361A51 for ; Fri, 1 Oct 2021 09:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352938AbhJAJTX (ORCPT ); Fri, 1 Oct 2021 05:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352972AbhJAJS7 (ORCPT ); Fri, 1 Oct 2021 05:18:59 -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 094E7C061775 for ; Fri, 1 Oct 2021 02:17:15 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id s24so6704670wmh.4 for ; Fri, 01 Oct 2021 02:17:14 -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=G9X7OW1UDA/WYYzzruAPJ7nNGMj7dQ/7K1KZ17Ee7W0=; b=PRb8BjEu2PW1kFVUSev2qlsfgVeM2Iu+7TOX39+hUAe+k/GFq0L8cBZsBMzXRmyXdD fa39lVRhpBK5ktHgdYRRXCdELBlRSWr+t7y6L+gBVxTWy2MX4vhe1l95HIDR5TXGIz0y PB69mg+3QWOYZbxJ6SyeNA8H5y4ODwQA5MyMTvrspJ4h8/boH/xfNvo1YGDeL7kC9Ncw M0S3UNNeiIWg7NFGfTu9iwxIMiu6bgCcLx5WZ6T77UJSoSf1/S32xUNlJAhQvQA3OalR nprx/1j3y5cX2JR5/7kzlfBzDvJv7Z2GwbhR8Xo7SZJN+afS7E7uz5YQM7HGUlftRtY9 //Cg== 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=G9X7OW1UDA/WYYzzruAPJ7nNGMj7dQ/7K1KZ17Ee7W0=; b=Ehb/kxjh9vVyVxCN/8ZvMpko/tKVxKcUnpoWL6Iwa5kPTr+aClRSWdDZNhkzHQ3Vbv 3QWiR5ReAMwwtprtQ/xfsvg7m3RnxTjMA9Qx3KEQWAFtzbVFwSKxuQFIhSQQ97bQxsY8 BDFibnS4dspQ8RpHXop5XDvwHgxsakdaBDQPsSRwfwB/IXdVkqZH6GMgf2t21cHWKG9l BkMLORBTVHxD3cawf1i2P1LCisFePvOs0L9ofM7fj/qfxFIrSlPNs2Zrl/O/qMJUItAk LPH5gdlaC8coBBsdTRQPWfEmyGgAdQkmpmsXOSPLBZvmdyysokSUEMF3ygH0CLIlzl8t DOEw== X-Gm-Message-State: AOAM532nltsnmGeWUticu4iFjWfJU7el1IXbZhf2YIY+HMKMJ6bV+o3O GKACmPFyzsaew30yReBxJCPowhfFIzQszw== X-Google-Smtp-Source: ABdhPJx45AqBuvPAZPMOyhCXJzTuxdT5YOrdgDyaAyDDqnmRtpWIG6SUtzUfsUeGi0phQrGyD6ntzQ== X-Received: by 2002:a05:600c:3548:: with SMTP id i8mr939848wmq.165.1633079833192; Fri, 01 Oct 2021 02:17:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j4sm5301346wrt.67.2021.10.01.02.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:17:12 -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 v10 17/17] fsck: report invalid object type-path combinations Date: Fri, 1 Oct 2021 11:16:53 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.g5eed55aa1b5 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 | 15 +++++++++++---- 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, 38 insertions(+), 26 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 260210bf8a1..30a516da29e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -608,6 +608,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) void *contents; int eaten; struct object_info oi = OBJECT_INFO_INIT; + struct object_id real_oid = *null_oid(); int err = 0; strbuf_reset(&cb_data->obj_type); @@ -615,12 +616,18 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) 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 (read_loose_object(path, oid, &real_oid, &contents, &oi) < 0) { + if (contents && !oideq(&real_oid, oid)) + err = error(_("%s: hash-path mismatch, found at: %s"), + oid_to_hex(&real_oid), path); + else + err = error(_("%s: object corrupt or missing: %s"), + oid_to_hex(oid), path); + } if (type != OBJ_NONE && type < 0) err = error(_("%s: object is of unknown type '%s': %s"), - oid_to_hex(oid), cb_data->obj_type.buf, path); + oid_to_hex(&real_oid), cb_data->obj_type.buf, + path); if (err < 0) { errors_found |= ERROR_OBJECT; return 0; /* keep checking other objects */ 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 faf0e98847b..6337236fd82 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 ) '