From patchwork Sat Jul 10 13:37:04 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: 12368607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D528C07E95 for ; Sat, 10 Jul 2021 13:37:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D8DA613B9 for ; Sat, 10 Jul 2021 13:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231406AbhGJNkS (ORCPT ); Sat, 10 Jul 2021 09:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhGJNkR (ORCPT ); Sat, 10 Jul 2021 09:40:17 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 792FEC0613E5 for ; Sat, 10 Jul 2021 06:37:32 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id l7so15549990wrv.7 for ; Sat, 10 Jul 2021 06:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a0wtNCi6n9mi6lr0mjYqJ+R0Pn3kumfRQ63uTav2298=; b=flIKrnSE8visd7g5iJFTzaUFMAPPvmquyI/FxsEakDZr4rQ4tC0MMQESwqdQmBAap9 iqwrfst8i2E7yUDWZr02dbg1gghrHecCWvfW/KaBA8ZGxJXpXiArfqj6mgCBrh/tdzg6 Gd4El+dyVvVVQBYlit67veMrJ/KCb5KTktblexTtcdL3iBWhDRYwgkYztVkB5y4AWPJE h2f1bWuJom8jmM2XvP3GEhuJFUCiGKoNENjB/Vs6M2zdQse6O1phTaQwHz/HVyQWW7lc YxKwZi6T73sKUsd99sWCqScVhAmKn2VGpQalzLYKBoug7EKVkPq8bjHactN3urcWyJAN 8XZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a0wtNCi6n9mi6lr0mjYqJ+R0Pn3kumfRQ63uTav2298=; b=RBmf44HM0PBuXfNnh9PBPt5el4VgY4ARnDI52oT+bF9+1u7H0ectXuQ/XrbOx1zDZw a5qwSD7SnyqRfPh7LuAz5aTIcGLoMFTwvc+6XqflbcEHCyvhQcCINAw6zXtiYBAPeq7O hrLWbVMMicj11vILj83Gr/KFt2IRcUemL5LNXADjzuwsUZ6FGuXEUJBoO0sbahcCfCvY XODPZuxxRNzw2ck/trigKh0Fu9uIXT/jIOHh0jpPzywR6SZWD48rm6Q9lZzBWrRVRToy GHfBbsJHIPVSHXXjjjtTEC2mJAdahLUnaRX/x5FyzFUvod2VWUwtA5kIoiDL1MaRrTAc oL0w== X-Gm-Message-State: AOAM533JxhaY4G/et03DQdVQchS7Poeoa89VrMABSU3M0EzHKIBSn09E VGUh3hXSobw86mSOOk5wchdcNuNRfXwJIA== X-Google-Smtp-Source: ABdhPJz5Zo/O3rAc8dPEZVsVQ7gbc4mx/mBDy1QOEyesMXQOs8vDpxQbiqK1gj+pNJ9A6doukMEllw== X-Received: by 2002:a05:6000:18c8:: with SMTP id w8mr39369182wrq.90.1625924250710; Sat, 10 Jul 2021 06:37:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 01/21] fsck tests: refactor one test to use a sub-repo Date: Sat, 10 Jul 2021 15:37:04 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 should instead simply use something like this test_create_repo pattern. It's both less verbose, and makes things easier to debug as a failing test can have their state left behind under -d without damaging the state for other tests. But let's punt on that general refactoring and just change this one test, I'm going to change it further in subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1450-fsck.sh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 5071ac63a5b..7becab5ba1e 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -48,24 +48,22 @@ 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_must_fail git fsck 2>out && - test_i18ngrep "$sha.*corrupt" out +test_expect_success 'object with hash mismatch' ' + git init --bare hash-mismatch && + ( + cd hash-mismatch && + 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 && + test_i18ngrep "$oid.*corrupt" out + ) ' test_expect_success 'branch pointing to non-commit' ' From patchwork Sat Jul 10 13:37:05 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: 12368611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C30D7C07E95 for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A13D4613BE for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231631AbhGJNkW (ORCPT ); Sat, 10 Jul 2021 09:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbhGJNkS (ORCPT ); Sat, 10 Jul 2021 09:40:18 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A43BC0613DD for ; Sat, 10 Jul 2021 06:37:33 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id g16so6586315wrw.5 for ; Sat, 10 Jul 2021 06:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OgnxKgzRElTXk1BTXxILsnwfavRXDyy4w7BU4Z0hWws=; b=U3DUCqc8pg9UsMVN4DdC2aqnspk+c0oLHM4efVtpcSA4mrRzZNtA+Rjs+Np5cxMttF DBYm/sonRrWAcbwOxEaFLmv3lIV/65W+n6IS0iZ56TiTbCLOG4ZXMamS5IsFJBXq5o/O 0tJdMyt2y59wTv2uygT45FFutcXOFECsGRjGadOr7bk3Tdyo3Z2xuOjryruigUW2K6LH vTEqBBxdN7oIkFzRYwGFs3tf2KiiWGLaN3YA9EweHTh3jt8rjJaovylYur/TfYKn8R8t rlctZ17ePZOrHfDtSJTlILf5iAINUK+1Vbkox2QTeHxCmkx0EEU1lAXMdUCv/cSMsBGf x0Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OgnxKgzRElTXk1BTXxILsnwfavRXDyy4w7BU4Z0hWws=; b=kT5yoLa/tVmSjydgTxRXngqrCl8OwZ4mwnnjKEZLU5VKweyV2s6lM6PsCgRjV2y4dl QG0rZl0y5zxgTEbRxlSnYljs8GkrbtI25qM3p5PMk8BGAWA+4/o41gdgjTP7NPmhBv88 ZhcK5GAYODcfD/b0L5iVuwgRaNuxHrNIoNuINm5V4u0iyTMaKOx4oORXgwS7rFrsrS/e iYs0TwlYIjyqLcCwDY9d3MwUAH9C8rfTcyk77snyFOvVcGaJSo0rL3yRxvdn8BzIX0Se t5IbQGoeHcKu0jJ14EQ9UyKQe9p+kHb1bDzDCnpgyTWYAsAA3rRMWBDiCfa5nKbEr036 NHeQ== X-Gm-Message-State: AOAM531U0eXmrayAfK1Z4Ktdaafh9hSiuvk5TrtKgj5eWmKUw+w/a8Gy rPY0bQotSKsR7lVQiA8pt2Vosg5ymm8QBw== X-Google-Smtp-Source: ABdhPJxQyzi9hidaZ6p/3KMHbZrOE9Sf197/ugRqLxVE0vU2VqGyfqXmyI6z0buvM036ZJLcGDwfQw== X-Received: by 2002:a5d:6b91:: with SMTP id n17mr19893650wrx.385.1625924251516; Sat, 10 Jul 2021 06:37:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 02/21] fsck tests: add test for fsck-ing an unknown type Date: Sat, 10 Jul 2021 15:37:05 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 7becab5ba1e..f10d6f7b7e8 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -863,4 +863,16 @@ 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 && + empty_blob=$(git -C garbage-type hash-object --stdin -w -t blob err.expect <<-\EOF && + fatal: invalid object type + EOF + test_must_fail git -C garbage-type fsck >out.actual 2>err.actual && + test_cmp err.expect err.actual && + test_must_be_empty out.actual +' + test_done From patchwork Sat Jul 10 13:37:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03648C07E9C for ; Sat, 10 Jul 2021 13:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D82F9613BE for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbhGJNkY (ORCPT ); Sat, 10 Jul 2021 09:40:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbhGJNkU (ORCPT ); Sat, 10 Jul 2021 09:40:20 -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 0AA50C0613DD for ; Sat, 10 Jul 2021 06:37:34 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d12so15872096wre.13 for ; Sat, 10 Jul 2021 06:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iTnt6aosZv4I1xd0MnkZClCVAvdXvk6HnGgTKFePhko=; b=fUijFGNFcWTpKZu4IoNgHlJJzb/mvxe2QV5Ku2RtEPXDWSdfJSbxfSwFYCJRypSGj7 /Ua9pSUQ4P2ULTIZ5GlICwVpNG/zx+kZsnNZsNLJ/DrxaEmrbSrty9s497AICSez9Kuk t975wFS1M44fRM6dO6bfy9LyJmQQ5CRnCtZJzPpCiz1DP4L8rdAaKhzh0Izt0DIvizZj n7tviM+k0mL1eJjr+v39LoBuTen0RN0oswFiDPbp6L1SrMyvyhhLhwO8Ce0yM9lgM2kS inVnHVti1dgmcRPn/4vZ4REbQmAWyPUaXj0tiAcVApt2sKeNH/0ym0TayrGAYhakX6jg m1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iTnt6aosZv4I1xd0MnkZClCVAvdXvk6HnGgTKFePhko=; b=iMZLPGJBAScp/7tCG+9WDQnSOlrfur6oFDAfqlBz7upR7VPlSZ0op3iS+NvgnGOGla DlwOmiH/fWnqh5F8WylUj961EnnNbjKflgqtE0XDvQT+IgItoJAGrL+3ZuENjFINX0qK GVJV+kHjkyG1cd7Z8VGqM+qZfwhP2QqZDL5AGhabjoCA4605nUjDpZhQnCFaW8Vj43nY RUb+fkXLeK282vx2dmAyfDmWBUtG+cJQNd4HSHVI+wEcAli8NMB7o/+jq2oMMY8F4E6B m11LDqbBhWykpKNcqym1uxlCBUK9Odd94nHNl+wST7TfXf+ZUvEWuX4yrcUM9ECCh1zX 3/qQ== X-Gm-Message-State: AOAM533Xz61avutqHAvaSUlt0t98wSwoNWxQ895T/qspLqT0T+rKsbj/ tsZcmEW7BGraYxYFXbRfoPyxQmfJ4mM4Gw== X-Google-Smtp-Source: ABdhPJyUZAV/43CZ84K4/YJ3RqYgbjZw4SzhoPxji7RVV0o/+aDNJIkat8eSs/CYiNhuFW8AS/9Zpw== X-Received: by 2002:adf:f90d:: with SMTP id b13mr38364099wrr.336.1625924252393; Sat, 10 Jul 2021 06:37:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 03/21] cat-file tests: test for missing object with -t and -s Date: Sat, 10 Jul 2021 15:37:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Test for what happens when the -t and -s flags are asked to operate on a missing object, this extends tests added in 3e370f9faf0 (t1006: add tests for git cat-file --allow-unknown-type, 2015-05-03). The -t and -s flags are the only ones that can be combined with --allow-unknown-type, so let's test with and without that flag. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 5d2dc99b74a..b71ef94329e 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -315,6 +315,33 @@ test_expect_success '%(deltabase) reports packed delta bases' ' } ' +missing_oid=$(test_oid deadbeef) +test_expect_success 'error on type of missing object' ' + cat >expect.err <<-\EOF && + fatal: git cat-file: could not get object info + EOF + test_must_fail git cat-file -t $missing_oid >out 2>err && + test_must_be_empty out && + test_cmp expect.err err && + + test_must_fail git cat-file -t --allow-unknown-type $missing_oid >out 2>err && + test_must_be_empty out && + test_cmp expect.err err +' + +test_expect_success 'error on size of missing object' ' + cat >expect.err <<-\EOF && + fatal: git cat-file: could not get object info + EOF + test_must_fail git cat-file -s $missing_oid >out 2>err && + test_must_be_empty out && + test_cmp expect.err err && + + test_must_fail git cat-file -s --allow-unknown-type $missing_oid >out 2>err && + test_must_be_empty out && + test_cmp expect.err err +' + bogus_type="bogus" bogus_content="bogus" bogus_size=$(strlen "$bogus_content") From patchwork Sat Jul 10 13:37:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07F8BC11F67 for ; Sat, 10 Jul 2021 13:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4C15613E4 for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231972AbhGJNkY (ORCPT ); Sat, 10 Jul 2021 09:40:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231446AbhGJNkT (ORCPT ); Sat, 10 Jul 2021 09:40:19 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7717C0613E5 for ; Sat, 10 Jul 2021 06:37:34 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id r11so11236852wro.9 for ; Sat, 10 Jul 2021 06:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=viEWWk6phoDHWfOdK63uqB8zG5Y9a4Lvz9yYgEHac/Q=; b=aytRNvrJOEf8RIjwMLV7N+fxCg0NlPkR1et0DLHx+n6WpwUqoLT9ZkJJsYqoNsL/jv T4T2bsPR3tqylZE1X/VYyTYDHuQAahreWFxDJ+E702JlJ8WVIf92FYt8ISkke5mYLTgT BemqyIJrbU2zBJgf8bvh4m+4koccKpvaoxDEQ5JisnlF88DgIKjh3uDXtST87lYbU2ph FJzoAFyL8ACzzb4nI3C0oCSoVBOzNwWukUpiNnxMjnvIh0BMe8WDCVEXm5TdKSktDFbO 3OCmw0/lBFkvTZYEBzlMxEAXxkcGEQOw8HJl5Pjg3t2YhqgbJltM1vXzojADM7bdYea+ mBww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=viEWWk6phoDHWfOdK63uqB8zG5Y9a4Lvz9yYgEHac/Q=; b=l99E9wEfOSBVASR5GpWRYmblY5fRm76qry7M88VsORaj2T1zkeiqQCdrvpEgtEXLEj 3DNyzCpoYHwzwYZ+74RzWVQ/8Y2+/K5nNlXoulJl94cdKr4yxXLeqEmwAAm6Wosujw1w UqiJuyxFizswSTEwN4rFwr3ASbxlbGdRFXIbsh3wMIPEN0cZDwix0uJt1qUrGq3HrnbO jyZjsLQZkslLYrgAuxJIbRL5NSpTktopDCJZ/xyU1lNFK0kxNloX8OXI+cz66VBM5vLe ay8iASVI6L8/7D6QposPzvy8bj3UOeMA8O/vjcKqbgRAvBV6Z770j4gXWcjRqinbhwjK Qc8g== X-Gm-Message-State: AOAM533lM7UN8ta98mNQwOGfkt0zGdUrzAP5TvJtJ4xaqreyeo+YZaZ8 kfxhtBsQxGmMbE6JdkJzRh7On5xHI5kezQ== X-Google-Smtp-Source: ABdhPJwMPJ+81KU29H064Fnx4r4LjsxIYvj7k7yr9BfxfVHwC0VpgiQxGfGB/P4wJaHQ9ICs1ntsqw== X-Received: by 2002:a5d:680e:: with SMTP id w14mr48166207wru.58.1625924253210; Sat, 10 Jul 2021 06:37:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 04/21] cat-file tests: test that --allow-unknown-type isn't on by default Date: Sat, 10 Jul 2021 15:37:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 the --allow-unknown-type feature added in 39e4ae38804 (cat-file: teach cat-file a '--allow-unknown-type' option, 2015-05-03). We should check that --allow-unknown-type isn't on by default. Before this change all the tests would succeed if --allow-unknown-type was on by default, let's fix that by asserting that -t and -s die on a "garbage" type without --allow-unknown-type. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index b71ef94329e..dc01d7c4a9a 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -347,6 +347,20 @@ 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 'die on broken object under -t and -s without --allow-unknown-type' ' + cat >err.expect <<-\EOF && + fatal: invalid object type + EOF + + test_must_fail git cat-file -t $bogus_sha1 >out.actual 2>err.actual && + test_cmp err.expect err.actual && + test_must_be_empty out.actual && + + test_must_fail git cat-file -s $bogus_sha1 >out.actual 2>err.actual && + test_cmp err.expect err.actual && + test_must_be_empty out.actual +' + test_expect_success "Type of broken object is correct" ' echo $bogus_type >expect && git cat-file -t --allow-unknown-type $bogus_sha1 >actual && @@ -363,6 +377,21 @@ 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 'die on broken object with large type under -t and -s without --allow-unknown-type' ' + cat >err.expect <<-EOF && + error: unable to unpack $bogus_sha1 header + fatal: git cat-file: could not get object info + EOF + + test_must_fail git cat-file -t $bogus_sha1 >out.actual 2>err.actual && + test_cmp err.expect err.actual && + test_must_be_empty out.actual && + + test_must_fail git cat-file -s $bogus_sha1 >out.actual 2>err.actual && + test_cmp err.expect err.actual && + test_must_be_empty out.actual +' + 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 && From patchwork Sat Jul 10 13:37:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE236C07E9B for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2645613C3 for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbhGJNkX (ORCPT ); Sat, 10 Jul 2021 09:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhGJNkV (ORCPT ); Sat, 10 Jul 2021 09:40:21 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4950C0613E8 for ; Sat, 10 Jul 2021 06:37:35 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id p8so16523119wrr.1 for ; Sat, 10 Jul 2021 06:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RW1SRHaWkbKF75XBFUeFetQ7HmluAjjHrZWZ3oFnjbM=; b=pLfE0rktRJGfB3owWoRLn5/UIBeyeSWJl0jxMS4nYFlRFgKcXiXKZhavlUhWG+/2CD fgzea+YwrWkSKmV8HyYFGN28KCiToVbKN2E5OKwdIfVfeaFVq8/V7JdA/EO1PfGmPrOb 2XS9LOf4DZQwCIXJPS+nuIE+8JUx6SXTcG+7fDUYfrkU1b0bNIiFsROJFv+FoS+lWlJ/ bWWGhaWgIljoocINmdSbke4OK+Sicx7uQMLw6HIHBv+UT87odAGexnQAfoH8p+3tXq8J omspgMnwGu7ZXy+khVEhKzrVU4wRILxf6iDX/itf647htXl+yjIjxIaqSnhQQWZWwpiH eRng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RW1SRHaWkbKF75XBFUeFetQ7HmluAjjHrZWZ3oFnjbM=; b=pG+IIiX8jp8wzuDQXU45SlvgvP9eH3tl06vlbw3SXtgONkBC88Clz94G4Ce+iCgcHd Yd1iJ9rDN7dcJVCcmK3Gu/COkf4+NTI+YwOfnte2dslOV5NTkIm4QnrrBbcF/L9h49RV d3vub9FTsrbqATtHOEIswu7yUs3UxN6jiiwoZ8AVW/5UIOPrbWO5kHSHZ8UTTAFNxhtr 4s8AsdnE7vuRY6SWp70CpUlzDxM3I9ZTTKfL2ZQK12y+GAa2dkisbF6LGMrEGGYwRiKG xCFuLYK8RQgqxi0wKOBYBABmLKfK4MXMmsX0FJq1eDpMBj22GlBQMrLX1S+xF3AEuDHz nb4g== X-Gm-Message-State: AOAM5336pVWDXgPur2Y/R6ApZ8GpJ2tK2QkdZR7rtW1GhmxDMuyXGo/d pG7pw9ZI+lDPeCtA7kr3eYJBsMRA//Ewhg== X-Google-Smtp-Source: ABdhPJx4qkj18hsqCeskkwe8fZn8RmefQ3laSJXtcD88WivLFYCJz4GSrOvyGOhUMHsQcJ9SKN0kUw== X-Received: by 2002:a5d:4b47:: with SMTP id w7mr48891094wrs.389.1625924254067; Sat, 10 Jul 2021 06:37:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 05/21] rev-list tests: test for behavior with invalid object types Date: Sat, 10 Jul 2021 15:37:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 the "rev-list --disk-usage" feature added in 16950f8384a (rev-list: add --disk-usage option for calculating disk usage, 2021-02-09) to test for what happens when it's asked to calculate the disk usage of invalid object types. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t6115-rev-list-du.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t6115-rev-list-du.sh b/t/t6115-rev-list-du.sh index b4aef32b713..edb2ed55846 100755 --- a/t/t6115-rev-list-du.sh +++ b/t/t6115-rev-list-du.sh @@ -48,4 +48,15 @@ check_du HEAD check_du --objects HEAD check_du --objects HEAD^..HEAD +test_expect_success 'setup garbage repository' ' + git clone --bare . garbage.git && + garbage_oid=$(git -C garbage.git hash-object -t garbage -w --stdin --literally garbage.git/refs/tags/garbage-tag && + test_must_fail git -C garbage.git rev-list --objects --all --disk-usage +' + test_done From patchwork Sat Jul 10 13:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA4A0C07E9E for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA2CB613DC for ; Sat, 10 Jul 2021 13:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231708AbhGJNkW (ORCPT ); Sat, 10 Jul 2021 09:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbhGJNkV (ORCPT ); Sat, 10 Jul 2021 09:40:21 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52103C0613E9 for ; Sat, 10 Jul 2021 06:37:36 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id m2so5457198wrq.2 for ; Sat, 10 Jul 2021 06:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U0Ggmi1d4Tujx9XzD7foLX+2TuPB8Vab8wiF9BadapI=; b=pThZPk3JwPiWD3hcerAiP6s+mUQI+75EYlv40jTnWp9CCJgkUtaOQz4Bql8ie40GNa G6zLUtyRPEk4A6vbJF0DJ6Vb35dOs0abe6tGRe63fnpXQHxUyM6c/ewLnPF8BmYtxiVN VhIE04ExenyvdThT5D7XiFLFsBkxompFT0dkVZw9+ACxQTUrKOqAjv5cDMVMJVarPvfG IOQ9ykR/XZE8xRbAnGEEsIrgJcioB3+Mwyr55q2VCXZ5BopOuSheLqOMvVxpJ9pEUVdm kHLSjvo61AxMD9JPi2wdycFAWRLSq8MFTh9hAYL/IdMImxMglu0XQadjOiQ1La8XyPHy gyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U0Ggmi1d4Tujx9XzD7foLX+2TuPB8Vab8wiF9BadapI=; b=gGLwHZ9wmIMk3BPSnGi0ifaKQ4QR/PbxGPPNTTo9nYRmPO1snwIGz5s7SB8O+cS8aV 3LRyyxFji1NNGM/QKp2ZnI/ZIlqJFl8lrPpikLs7QC2QS/9TWInCexWYlOpTKMjEp32G FEcGR1ptBLYK0D1M4Rto+rdXyUTwWlxAEpOA39Hotc3plYuJoTTR7elY5xthSw/Rg+a2 FCoU5e0ywdDM65YpIOkR3LVx5w3guTFOk4nMz5s67Tp1pmnSQvjP2wpa04iqK9dTdT0A TQ5OU82Jd+E3jy701Y5C/JoSP49a4RiLxAIoUc7Uw4BEZBEPN44yJ6J1LsdOUI5ZGq8g G+jA== X-Gm-Message-State: AOAM5316R80BWvtPFGugohUqMri7D9WkeRoOmcc0/d7OfBCmOMP4G9sX Jr56n5X8d/j6OFdV7xIqRHXTfByNe7Qkgg== X-Google-Smtp-Source: ABdhPJyktLCstfd8uM77kcvZmFPGLdiy9fIBIuNAX+1wQebTmJozGMLy2Zcvbe+VYqIs7wVeXUNPjg== X-Received: by 2002:adf:ef11:: with SMTP id e17mr10418092wro.71.1625924254740; Sat, 10 Jul 2021 06:37:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 06/21] cat-file tests: add corrupt loose object test Date: Sat, 10 Jul 2021 15:37:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 dc01d7c4a9a..7f10a92f0e4 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -404,6 +404,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 Sat Jul 10 13:37:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FDDBC11F66 for ; Sat, 10 Jul 2021 13:37:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E926613C2 for ; Sat, 10 Jul 2021 13:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbhGJNk2 (ORCPT ); Sat, 10 Jul 2021 09:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231745AbhGJNkX (ORCPT ); Sat, 10 Jul 2021 09:40:23 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2689DC0613DD for ; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id t5so2645650wrw.12 for ; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5xgIl1pTpg0BPbreigDZ4CheXIt1UgPqr3BtcDUT9xY=; b=QaNpcCv+3opECwtoximP1B3yCMIsT8zu1gERhwvx2F1CHRKAOYg7A72LqC52azMDeC kZ+LaWFutkKU7soQFBPkM/ai5A9XKOG1bt0AK9/GcV++ydrBYiAZOjOD4wWb45hQBTgb +m+F273XmrsVRa7bkGWERF/ivM2yVbJ7UifoFbdHE7q//JZowT5OxQt56bp02Y1UpNmp LvueCiwaBpzqCMK2lM1WZ+kVThnftaz1FqjUDrH76RomSp5mI/72d50AKc/bXcCA5wLd GKshJHwT1pPmMW545jxiXE5V5sJHNNI+27oyHoE1naG64/Rrngl2hdjRYBZRso75R/5c bM1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5xgIl1pTpg0BPbreigDZ4CheXIt1UgPqr3BtcDUT9xY=; b=dIZtpdttlEOIZBEZ1eYVpQw/eYkq2yoaAzNgRFEePkdvVaE+8RoR7hxtOy3ZgWOOsp mY3E2xGLu+6/57dFN61A37Da0SebhLZWD9TfDlubbab+TJKHJzAJUZGsrUkdpGjTwEnA Gc7rYfxRbUiBjHbCd5tlysxyx+ChA6osbOB+HGDqJ5rv4v/HSHUXo3eheKCJ46AN8Y52 CV7c7Ud8pJ4cXHaT2ZLPmEKhOTXH028yO8JlUxWrknjwS+Z9lnOA6X1CLkkYFpjV2bsD 9wg5MXvqkA8ZUNTINby7s3qM3CmdFWrv9A97elVNImMLL/ngF6bQjkKfKgHZ65f4g85T fkpA== X-Gm-Message-State: AOAM531Ptfoig80q+BAjwDvzbcXAkPSnWZrRwDyGmF88l1yrrrwhJTlu nEb9nmjCkoi/jaXHPx3vdhppDQwkFdmbdQ== X-Google-Smtp-Source: ABdhPJyAk2NoihiGqzvOPeE4L2cR77zxaVCqm4PycuUVL3CN0+llksMyz/Su0JyfC60OLZEju0nskQ== X-Received: by 2002:adf:f346:: with SMTP id e6mr31177803wrp.28.1625924255547; Sat, 10 Jul 2021 06:37:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 07/21] cat-file tests: test for current --allow-unknown-type behavior Date: Sat, 10 Jul 2021 15:37:10 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 7f10a92f0e4..86fd2a90ca7 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -361,6 +361,46 @@ test_expect_success 'die on broken object under -t and -s without --allow-unknow test_must_be_empty out.actual ' +test_expect_success '-e is OK with a broken object without --allow-unknown-type' ' + git cat-file -e $bogus_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_sha1 +' + +test_expect_success '-p cannot print a broken object even with --allow-unknown-type' ' + test_must_fail git cat-file -p $bogus_sha1 && + test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_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_type $bogus_sha1 2>err.actual && + test_cmp err.expect err.actual +' + +test_expect_success 'broken types combined with --batch and --batch-check' ' + echo $bogus_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 && git cat-file -t --allow-unknown-type $bogus_sha1 >actual && @@ -372,6 +412,27 @@ test_expect_success "Size of broken object is correct" ' git cat-file -s --allow-unknown-type $bogus_sha1 >actual && test_cmp expect actual ' + +test_expect_success 'the --allow-unknown-type option does not consider replacement refs' ' + cat >expect <<-EOF && + $bogus_type + EOF + git cat-file -t --allow-unknown-type $bogus_sha1 >actual && + test_cmp expect actual && + + # Create it manually, as "git replace" will die on bogus + # types. + head=$(git rev-parse --verify HEAD) && + mkdir -p .git/refs/replace && + echo $head >.git/refs/replace/$bogus_sha1 && + + cat >expect <<-EOF && + commit + EOF + git cat-file -t --allow-unknown-type $bogus_sha1 >actual && + test_cmp expect actual +' + bogus_type="abcdefghijklmnopqrstuvwxyz1234679" bogus_content="bogus" bogus_size=$(strlen "$bogus_content") From patchwork Sat Jul 10 13:37:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C0EDC11F68 for ; Sat, 10 Jul 2021 13:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08896613BE for ; Sat, 10 Jul 2021 13:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbhGJNka (ORCPT ); Sat, 10 Jul 2021 09:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbhGJNkX (ORCPT ); Sat, 10 Jul 2021 09:40:23 -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 C307AC0613E5 for ; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id f9so10817819wrq.11 for ; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CVPni73gs4971ioW1BEa0MP28Oob9sM+2za5h3/p1t4=; b=qxaBLB1hNdxGYMf2h3ASnCqxXiMCV70PMnRqhgyU0wtP4Rpc2HlHuc+2REAqwvPQG8 jM4AEjhscsPw6c5XxjdE1nYIN9At2Jasl9lQDX+rGgiYtAKvKTwwz69KegroS1e7k+9O j53NZ+D4cfMtBTu2Wqczuu5RxIkJYi7lVROwudfVbAJfmOzakh3D3y8NzCbOOhe8FEQ+ C6j/iqdy5xDw/ODXJXKIvO2i090xJcTL9Wc9gZMp29NufZB9eh0C5uAhhzBZ2K/42jE7 SER7W486KrM/ViCmM6AwQA+KLHxUy5Oh9oFz+1kPZHMznh/zDvWAOasBbzLmViVIq2Sc yIvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CVPni73gs4971ioW1BEa0MP28Oob9sM+2za5h3/p1t4=; b=Uc7bA0gLaYq5RnZYOFtSZtt6FsiART8AIN2SL5WvK4YarxQTDbF7S284dko22k0WQ6 YlxgfMf7+EQ13KUulyvfKo1Vi4bj1zepUOUvD8d1rL5/m63x0fXT/NdeI4kC2uIfHxaz Bg/upfm3JlLmIcy433Gx2+yVlXgf7tqrCiN5xFk4A+9lYErEEy27Kwz/rN2koQVQfuNz Voqcgqws8+SOW/uo4ydvXkGcYGVCFJcVSub+2CMe3PaH2SPpMz2smd2Ie7EKAd2SRE/+ fBofU/5HsbBPBX5PBR1N9yv+RQ46Z7VaCHF/IV5qJijhFrmQsOIjsxUCEEve7137UCpX JkLA== X-Gm-Message-State: AOAM531ahwwLfVWgwh9n6GBc2KLeuqElxyBxnryiqviFtpTt7HO9Ncas ryDSFjCADJvSIwGy4Nbim7pBJ3niJ0x6rg== X-Google-Smtp-Source: ABdhPJwDPMO6p+h8JkxvjASwMCYBedJu+DeyK9IV4IwmfYZkpf9etieTVBS9eN8XZt78j5kdgVORzA== X-Received: by 2002:adf:ce8d:: with SMTP id r13mr29183801wrn.304.1625924256221; Sat, 10 Jul 2021 06:37:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 08/21] cache.h: move object functions to object-store.h Date: Sat, 10 Jul 2021 15:37:11 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the declaration of some ancient object functions added in e.g. c4483576b8d (Add "unpack_sha1_header()" helper function, 2005-06-01) from cache.h to object-store.h. This continues work started in cbd53a2193d (object-store: move object access functions to object-store.h, 2018-05-15). Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 10 ---------- object-store.h | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cache.h b/cache.h index ba04ff8bd36..32ea1ea0474 100644 --- a/cache.h +++ b/cache.h @@ -1302,16 +1302,6 @@ 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); - -int check_object_signature(struct repository *r, const struct object_id *oid, - void *buf, unsigned long size, const char *type); - -int finalize_object_file(const char *tmpfile, const char *filename); - -/* Helper to check and "touch" a file */ -int check_and_freshen_file(const char *fn, int freshen); extern const signed char hexval_table[256]; static inline unsigned int hexval(unsigned char c) diff --git a/object-store.h b/object-store.h index ec32c23dcb5..9117115a50c 100644 --- a/object-store.h +++ b/object-store.h @@ -477,4 +477,13 @@ int for_each_object_in_pack(struct packed_git *p, int for_each_packed_object(each_packed_object_fn, void *, enum for_each_object_flags flags); +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); +int check_object_signature(struct repository *r, const struct object_id *oid, + void *buf, unsigned long size, const char *type); +int finalize_object_file(const char *tmpfile, const char *filename); +int check_and_freshen_file(const char *fn, int freshen); + #endif /* OBJECT_STORE_H */ From patchwork Sat Jul 10 13:37:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D401FC11F6A for ; Sat, 10 Jul 2021 13:37:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 977C06135E for ; Sat, 10 Jul 2021 13:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbhGJNkb (ORCPT ); Sat, 10 Jul 2021 09:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231827AbhGJNkX (ORCPT ); Sat, 10 Jul 2021 09:40:23 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A47EC0613E8 for ; Sat, 10 Jul 2021 06:37:38 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d2so16560069wrn.0 for ; Sat, 10 Jul 2021 06:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gyIFa+yysCsDInB7rQNvnAtkSlqxwlBqPaHoPa/Ivn8=; b=IfwwftglxICB+ayKbkY63ruKIQqXPt8vchvzOJO6em9cBA7LG43/8vnOoSFUtfqhdT /6wDWKAvqbTe2hdZCsPhzJiNSET+CsgiyU70KgdN7A78Cfg/cuH6ReqHJrDdxnZFsfq1 CONrdnEiZcmbr3Q9za97SUNSJ3/FHx2X2AVtSzeBp+KpSDmIfDIltfjoZKCeRvrHqAkb QQ087MQy3vxpnQDKC6tCFVDhLSzefhKMay+b9EMRUuR7dRkmbFzSi5XrH4PJXM68urYa 5r1fUT/vghgmgUQCJ21QiXhSCMRdN9K7YzTVvEcxI2kbp4HAwGPm60XA/CyhgVMb2XgK pvjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gyIFa+yysCsDInB7rQNvnAtkSlqxwlBqPaHoPa/Ivn8=; b=oBWSc/VGAMKCZT5gUw1UFKOnZ8GXaDROkffL0TBMJ9x3qu3c68FD6iC22AzPDAM2ei m3kjo4b+45IPZwTN02785J103Uz8vhRqm/tdNJnq1c+QmlDfHGDeknBFqnF0yuSUgB8T 7GK47Bir05U4olIyRxe50lBH993FdnTbmQVLb+orl1aK3h+UiayFTt+PkKewa6AMd1YR eyVmdU0OYgmaWW7uCTZ2veMxx70N5LjZ20VZD7He5fvd6FRYi0+D/ax8WYBWB6Bf6O/9 OmJ/PKvVvCaxtNyJ4cF2QmMqYYpngBPIE5jZdws5wWHvrOOPCNf4kiNL8VK0Wjnx15KW p9yg== X-Gm-Message-State: AOAM5339WryEK2CxKuCZsevb0mUSjXDJfCGluF8t4tcGU4LRP2/GMJuW AIz59Yq51LQJMgAdUMDV29ErGS5ayg0t7w== X-Google-Smtp-Source: ABdhPJwj+DkmzPCqtjyN1NwM+Z0kmsCvNNMjZ2BReRxakcDGkzTD53rI9xVJbXzbqYjGuIcScZbpkQ== X-Received: by 2002:a5d:4089:: with SMTP id o9mr7216100wrp.274.1625924257027; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 09/21] object-file.c: don't set "typep" when returning non-zero Date: Sat, 10 Jul 2021 15:37:12 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 f233b440b22..9210e2e6fe4 100644 --- a/object-file.c +++ b/object-file.c @@ -1480,8 +1480,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 Sat Jul 10 13:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D035CC11F69 for ; Sat, 10 Jul 2021 13:37:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9081F613B9 for ; Sat, 10 Jul 2021 13:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232223AbhGJNka (ORCPT ); Sat, 10 Jul 2021 09:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbhGJNkY (ORCPT ); Sat, 10 Jul 2021 09:40:24 -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 516A0C0613E8 for ; Sat, 10 Jul 2021 06:37:39 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r11so11237046wro.9 for ; Sat, 10 Jul 2021 06:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TjZnugTqggoGUsaWVV5GQ+xHR0Si+v1gl5QKGsQhthY=; b=lTCl54nFP7cNBkAOvcn8CSdsj4uMgIrbBSV2xnXS5zaWziCfbvmy/IxnZsw3ydh2kV CxPeris2NZ5QQrb/R1r8eH4IZQ6RxjDCWrUgUJa8j4mX0y+RR1P0EwitinwkhhPjNJgu AwOLxgy2rYsIzi94QHCN2veGsBbjrDbv2RbpmB0lFumJ3x9HP9X/qMHz2I8mF/GMkCPF vxuxuU8EvTiwRXuPCgaGn8ABdPkZYBa1eZ5EoUY/QhrdktKA1thSjwt/xvgUO38sdPmP 0PGxZlWXN/ke1kor+u9tSUQGvArSai2lNPVpbPuNxdxkJg34D8Wu/5hHl306eRSbEN68 5bQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TjZnugTqggoGUsaWVV5GQ+xHR0Si+v1gl5QKGsQhthY=; b=QzGLtf9rhEeqVFqggsvbYKqcOJZod4eSZBM1HhgiJAlHbaBYUIbRCQ7PiIO8IgQx+y KW0jKatpMoQBW0i/4iUCRbkIpdaxGLwdzHnv/bLEI8IR0+e5I5vvPSZ2JTb5GfwfCJzn KljtAoJ30TNQxfLGPb7Gn2pyu2kPwWpYkfhNd1vD2ht1lM7Mlg8rmf+/jxWnKoENLtn2 AT3jkOzk7LX1OZY3LuSvJi0kCTU23K6OaJzya3vWhXwLLMsCHUyWyVyYlBs5/o9fSLj6 qFYRE7o/wgzhynutu0KmNnDkd59OXFnnBkFFQWkAzrPmK0ZGwwnOwhSoGkd/9tqPUQd0 zfpQ== X-Gm-Message-State: AOAM5321dsWwKa+W8pdfw9XgTChxlLpgmcRmaRKfXyiTVxbJqD57vAsb OxZz5gYODML++gSrMrnz8c+R643dEtYVSA== X-Google-Smtp-Source: ABdhPJyfPhUOzef/Ih0cP6HpU07QyriZU5lYj8E1IAn35YXTDic7s2z0dFZmYBOHGjFzwZtNPqPX8g== X-Received: by 2002:a05:6000:1043:: with SMTP id c3mr1201658wrx.13.1625924257758; Sat, 10 Jul 2021 06:37:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 10/21] object-file.c: make parse_loose_header_extended() public Date: Sat, 10 Jul 2021 15:37:13 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 21 ++++++++------------- object-store.h | 3 ++- streaming.c | 5 ++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/object-file.c b/object-file.c index 9210e2e6fe4..e0ba1842272 100644 --- a/object-file.c +++ b/object-file.c @@ -1340,8 +1340,9 @@ 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; @@ -1401,14 +1402,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) @@ -1463,10 +1456,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) { @@ -2547,6 +2540,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; @@ -2561,7 +2556,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/object-store.h b/object-store.h index 9117115a50c..d443964447c 100644 --- a/object-store.h +++ b/object-store.h @@ -480,7 +480,8 @@ int for_each_packed_object(each_packed_object_fn, void *, 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); +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); int finalize_object_file(const char *tmpfile, const char *filename); 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 Sat Jul 10 13:37:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14C03C07E95 for ; Sat, 10 Jul 2021 13:37:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D14986135E for ; Sat, 10 Jul 2021 13:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232427AbhGJNkd (ORCPT ); Sat, 10 Jul 2021 09:40:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbhGJNkZ (ORCPT ); Sat, 10 Jul 2021 09:40:25 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E5B6C0613E5 for ; Sat, 10 Jul 2021 06:37:40 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d12so15872340wre.13 for ; Sat, 10 Jul 2021 06:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=goA2z589frndjbLtysr/eL3FhfWEVNYdFiFpgdYbtig=; b=VYSB9fv87sefrQk3acXbtL6ywdi2s71VPIGEaGm6nv9MKJerMA+YGcto/FdFdQXjbL 0gHssOAHtX9zOR7+XQa4mJ4sY/ZPBn8aIIi/Lm9+6VykURRYwyJ19QbafqZu4laDkT6a AHbmr6tX08K3khGYOtKTSO2SSGC1xLmZkYcsga2pa9DI6Yqzr+j/wEG8YbkyVASWsqJK XUvxNLxu8fwkjDUFTpcSQjsT0dTq0cWpp3s/IMDUaXvCZRSalwPMhSn497HVrdw3T9x4 YhCT3H0f/Go9x75DF2VLxhs3wO46lThGtlvIWoIo0cvd8s4AvDyui5Q9vRv/bzaEQYlG zPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=goA2z589frndjbLtysr/eL3FhfWEVNYdFiFpgdYbtig=; b=o3gzF8yUmAMNvDk+S6RGSxrlm+TVfbst7q41RH7NVK/LD1Tk0tjWhnjsjwZB2Fu8G6 RtKKsD98xsQ1zqeI9WEtP7vMH0YUgp9NlCA1yqBpU2A66qRksDW9NszOvCIGculDXaCi 8G7qnLDEkbYEGC4x93QNKohRYIz5M63qFq1xgnRX/Fv+cYJo9Iqdt6u7SaaW8JPMtDLh UQ94gYYIrSZEJQ9iMakypZqHmOSZMFvwAhMFKjOHCVzMfAGTCFi+sXk59b/cBu0ZiAG4 jQyoAAn4xrfUi5wqWoXAL6+8ID9gpG2VWNe902xLzu2kB2O0U/qziJT+qLMl5ivGKO/s TBFw== X-Gm-Message-State: AOAM531XmNV7ix1ZblTtsKN0N7Y2hA1XPLgdblXytf62tN8x1Z9Ubzxo W7ESWLX75lk6DGD6tsXOibJ/Itx/Oqzcfw== X-Google-Smtp-Source: ABdhPJz8dv4s5tfI26JJ35gQX5+vtmvmA7K5u0oP0V8jrcNiB5lwp4Cp1q855/UAkXjOIXDWdZyi9g== X-Received: by 2002:a05:6000:1375:: with SMTP id q21mr15932791wrz.147.1625924258496; Sat, 10 Jul 2021 06:37:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 11/21] object-file.c: add missing braces to loose_object_info() Date: Sat, 10 Jul 2021 15:37:14 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the formatting in loose_object_info() to conform with our usual coding style: When there are multiple arms to a conditional and some of them require braces, enclose even a single line block in braces for consistency -- Documentation/CodingGuidelines This formatting-only change makes a subsequent commit easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/object-file.c b/object-file.c index e0ba1842272..646ca7f85d6 100644 --- a/object-file.c +++ b/object-file.c @@ -1450,17 +1450,20 @@ static int loose_object_info(struct repository *r, 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) + } else if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) { status = error(_("unable to unpack %s header"), oid_to_hex(oid)); - if (status < 0) - ; /* Do nothing */ - else if (hdrbuf.len) { + } + + 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) + } 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, @@ -1469,8 +1472,9 @@ static int loose_object_info(struct repository *r, git_inflate_end(&stream); status = -1; } - } else + } else { git_inflate_end(&stream); + } munmap(map, mapsize); if (oi->sizep == &size_scratch) From patchwork Sat Jul 10 13:37:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4432C07E9B for ; Sat, 10 Jul 2021 13:37:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A41576135E for ; Sat, 10 Jul 2021 13:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231792AbhGJNke (ORCPT ); Sat, 10 Jul 2021 09:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232084AbhGJNk0 (ORCPT ); Sat, 10 Jul 2021 09:40:26 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01FD0C0613DD for ; Sat, 10 Jul 2021 06:37:41 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id k16-20020a05600c1c90b02901f4ed0fcfe7so8054565wms.5 for ; Sat, 10 Jul 2021 06:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L5H4hFaSm9UsltCDDCgD6keWG6HJ+dGf9zSZhGWm27o=; b=iGkTeIpwygGWEErWwqgPnwX5aH/3pipEBJ3RYGZkxz5TSafXvjh1oBrn8uinDyrCLJ 7coQYpjDDxpcFaH12BE9fOvR7u1/2XnzpL8Dq5SNLoqliJkljG8IR9nJ1ukAxoPc7n/o PnZpY+JDKH/EL9aRcRGN2IWKyHk2cUmeNy7WwQfbw7H8VpUVJ4+EDkTygZ7tclcMZtkF dkrkNmAhlUBKNyi3ouOrK+ccAh3dg6cL+pwh1//3CgjqVG8Cj/mK047i/SaICJKmqB5V wL56x69CUyTRvI2z5XmVjWVlJpSJxQOSoMw034pYskL9IT4qwS8B7aqTTyEtgU3R18y7 yr9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L5H4hFaSm9UsltCDDCgD6keWG6HJ+dGf9zSZhGWm27o=; b=phsftaKlHLkBSXFt6SbEjKqULZ57y2gTVVjAOokmBtVSIG5l/UlvlMfG/qE6YixeZP wJdjg+6ShinRDke4Tu1AHghX0MS7IfdNiasFHEKWr0V2kniRDlXTutI2KoC80+1u1ATq ZTcuzeDJ+kE1HtFcQ0ha4eNr2jaQmGqT3LbhIIFYMPpl5iVwTLlnTONdbymQFfIIk9Nf Wugia+fjmCd7XtXTW4+iUXZQvqRx3buhIrJ+g0k1cRq8bDjRLFUtm2ssfPPlLMGNACUm pmUa2Pvc6GC+QXO6PsYBl7QBOl6iaRxm8bpNAzJd0gnsae+jmyPn0hJqrO+wE46Hmeez v45g== X-Gm-Message-State: AOAM531ozjxd/73hSv9DBKDyI1jy4AzFefjZ5iHCmOm3+4v7rkJe58Rl 4bPVOss0ooJaKPsH/oyNhA8HX+OnNr4qUw== X-Google-Smtp-Source: ABdhPJyQQsxA/5UOJUep121MOIPfEKlip+KW+fd6kAuQ3E53UHQqucG86MExoT0p+2R+z8V9wmIs+Q== X-Received: by 2002:a7b:ca43:: with SMTP id m3mr45167512wml.74.1625924259309; Sat, 10 Jul 2021 06:37:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 12/21] object-file.c: simplify unpack_loose_short_header() Date: Sat, 10 Jul 2021 15:37:15 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 --- object-file.c | 60 ++++++++++++++++++-------------------------------- object-store.h | 14 +++++++++++- streaming.c | 3 ++- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/object-file.c b/object-file.c index 646ca7f85d6..ef3a1517fed 100644 --- a/object-file.c +++ b/object-file.c @@ -1210,11 +1210,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)); @@ -1225,44 +1226,25 @@ 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 status; - /* 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; - /* * Check if entire header is unpacked in the first iteration. */ 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 @@ -1410,9 +1392,11 @@ static int loose_object_info(struct repository *r, unsigned long mapsize; void *map; git_zstream stream; + int hdr_ret; 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); @@ -1446,11 +1430,10 @@ 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) { + + hdr_ret = unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), + allow_unknown ? &hdrbuf : NULL); + if (hdr_ret < 0) { status = error(_("unable to unpack %s header"), oid_to_hex(oid)); } @@ -2555,7 +2538,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/object-store.h b/object-store.h index d443964447c..31327a7f6c3 100644 --- a/object-store.h +++ b/object-store.h @@ -477,9 +477,21 @@ int for_each_object_in_pack(struct packed_git *p, int for_each_packed_object(each_packed_object_fn, void *, enum for_each_object_flags flags); +/** + * 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); + unsigned long bufsiz, struct strbuf *hdrbuf); 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, 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 Sat Jul 10 13:37:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F6ADC11F6B for ; Sat, 10 Jul 2021 13:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63A5E613DC for ; Sat, 10 Jul 2021 13:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232208AbhGJNkf (ORCPT ); Sat, 10 Jul 2021 09:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbhGJNk0 (ORCPT ); Sat, 10 Jul 2021 09:40:26 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B79DAC0613E5 for ; Sat, 10 Jul 2021 06:37:41 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id l7so15550436wrv.7 for ; Sat, 10 Jul 2021 06:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1QnITdhbhJb6RSVllzyHVCA++wj+9v8pQ16hg9kwVic=; b=el6qHkYwh8BRKG5cpSKbRvZznhBNbKba2ZRLoHxQ85pCdyc5ig56/1z7JF4SgOtcUJ i7jGLibH2vwMkCmfCkCqB7ahDha5G8rL2IPaAr6GwoRqgvfCFILuYtXq6HQ3dRdPrpcv 10MraHcaRhQg+Z50su/ZUGs8jwuHJ88+QHAtdSQCcrwlwc/XiSnRDKmIc5edRd+Dub8b 55r+8k0VS9RZGEs34A+PITrFbnmLtgcHYr0KPpMoCpL8E8Mp1pAxTlEv0ZlW6uTRJrKq v4xWLoAT4UdqscT3TUam02ZYUxn+FF7lx6DwIztTgII//tDOLpQN/d3e9Igd680G+6jV Go1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1QnITdhbhJb6RSVllzyHVCA++wj+9v8pQ16hg9kwVic=; b=NzF/MVH4Ugqv915I9iXm8aNpkV5dyTef0tHTeUqnAXIx06+3anB+Vyae+Qm8Yu/YHg YWf4CbMuUqeiqQU89IQ2FgIo+3ENA1LWjDeKaeHcVAuRWOyjhOBNYmzvdZCUekYRVuKF cC6tr20aTsWptsL2SvElcRt0vF/F7fr2qq1AavN7tjQ8ih/81qo68q4pKWxBWjnzhoNk Gq0WuF7T7dFm347qMf/s2FnWj/f4HOxBscluoAhBCs5CD9NkVlDo7Unfyz/vSlO7eFRu YMMCuOoV2zEqftEuLOX3h341qqN8pVdJCZECXtoqsdYzfM1/S44cZVBvNgZfqHVbOPxA BZHg== X-Gm-Message-State: AOAM533YZm6RfYXhWk7IXpB/LFk327HMdn29TuwEMjZNmGv4mTZnNR+0 ybGtbEYhcVHCJla5qOa4yuXgf08iBxY2UA== X-Google-Smtp-Source: ABdhPJyo8sRI6fEPXwkPBKTvFpo2rDQNTRWNeQDBMtDxFGc4tuhSrx/cN0RSlLkyQOvcd3901PhPPA== X-Received: by 2002:a5d:4c52:: with SMTP id n18mr1891011wrt.295.1625924260151; Sat, 10 Jul 2021 06:37:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 13/21] object-file.c: split up ternary in parse_loose_header() Date: Sat, 10 Jul 2021 15:37:16 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This minor formatting change serves to make a subsequent patch easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/object-file.c b/object-file.c index ef3a1517fed..e51cf2ca33e 100644 --- a/object-file.c +++ b/object-file.c @@ -1381,7 +1381,10 @@ int parse_loose_header(const char *hdr, /* * The length must be followed by a zero byte */ - return *hdr ? -1 : type; + if (*hdr) + return -1; + + return type; } static int loose_object_info(struct repository *r, From patchwork Sat Jul 10 13:37:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1118AC11F6C for ; Sat, 10 Jul 2021 13:37:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0A096135E for ; Sat, 10 Jul 2021 13:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232012AbhGJNkg (ORCPT ); Sat, 10 Jul 2021 09:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbhGJNk1 (ORCPT ); Sat, 10 Jul 2021 09:40:27 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD31CC0613DD for ; Sat, 10 Jul 2021 06:37:42 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id g12so188134wme.2 for ; Sat, 10 Jul 2021 06:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yg0ZGXoTqMbjYLjrtvFW3iKFZZfWj5kVuNc0ocz3ShE=; b=un9cdNuIxxX/6YD7rPYNMGY7R9MpBzIKVoNtEGBgbZHjU9pNx+2rWObtnyR0nk3h/X DLcYibv23tp2guAuLUeLtT78eeielYC5SzQQggeWNeOjgp5oHJv8aVl9RUG3sunuNfPY QU0ECOEh1z+IZBMC4U62qXdRzD+dEGLhwEtNcRwE7gAEXHVuRt5ACVCz1+Oigy6E0ggL P7Eqzs1qjt2D40+ph+p++zSZnog+k4P1dpQdQMwdWYkSKuQ06lZrhhetBadvjNrS2LB+ xEQovAlvjloM0NJCKq+5sVjorseC2POz6z2K/9ip0FhaLOP26SSkVB85CcI2bu9blmVr zzsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yg0ZGXoTqMbjYLjrtvFW3iKFZZfWj5kVuNc0ocz3ShE=; b=qbF9Vtg4POIaBNNo38ElNShrtrHFwXR5iNnskBu7AGkG9jQSchdtNDkIzxj4vQNKAf rxV5t+HXt03GGieDZyxAWhoBRiz4BS+x53dLp5TsJC+Dkv/O94+DEklvUdSt9lUw7UI4 ZFq66Ats4dToxDZLWmwM5HXw8Si7ITuC1PmKieHyVT4D4TC4b76LXLxe5GOG4Y8ta6Ua MlZwrSNUHpJmokCBKIsToA7SJT813rxcvFAhKKAXCEh60RXLqc8nmTQfI64F/KixokwT knB5lEBCVHdXr8C+/ZSFj51Ib9os0IO8U3mo5YevHd9f8dK6YQqCBQk4sEC3V+tLZVLX a9DQ== X-Gm-Message-State: AOAM533U59BVLwECmxDj+XDF4pG14+baMg7TVgkiRVLIpzaQd+xH8yTM NnZbcKT3cJCYQHmBuGM0T2ARJXqIrbQmkg== X-Google-Smtp-Source: ABdhPJz+plaiyoV6gftCcekqUJubZLuOpzsC8arwemM/LrPhDpdF22rl1KDj6L5Y6eHqYgZJvDrDNA== X-Received: by 2002:a05:600c:1992:: with SMTP id t18mr4551780wmq.165.1625924260997; Sat, 10 Jul 2021 06:37:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 14/21] object-file.c: stop dying in parse_loose_header() Date: Sat, 10 Jul 2021 15:37:17 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Start the libification of parse_loose_header() by making it 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, but in subsequent commits we'll also libify those. Since the refactoring of parse_loose_header_extended() into parse_loose_header() in an earlier commit, its interface accepts a "unsigned long *sizep". Rather it accepts a "struct object_info *", that structure will be populated with information about the object. It thus makes sense to further libify the interface so that it stops calling die() when it encounters OBJ_BAD, and instead rely on its callers to check the 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. In another case added in c84a1f3ed4d (sha1_file: refactor read_object, 2017-06-21) (but the behavior pre-dated that) we did checks of "status >= 0", because at that point "status" had become the return value of parse_loose_header(). I.e. a non-negative "enum object_type" (unless we -1, aka. OBJ_BAD). 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 53 ++++++++++++++++++++++++++------------------------ object-store.h | 13 +++++++++++-- streaming.c | 4 +++- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/object-file.c b/object-file.c index e51cf2ca33e..31263335af9 100644 --- a/object-file.c +++ b/object-file.c @@ -1322,9 +1322,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; @@ -1346,15 +1344,6 @@ int parse_loose_header(const char *hdr, 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; @@ -1384,7 +1373,11 @@ int parse_loose_header(const char *hdr, if (*hdr) return -1; - return type; + /* + * 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, @@ -1399,6 +1392,8 @@ 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 parsed_header = 0; int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; if (oi->delta_base_oid) @@ -1430,6 +1425,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; @@ -1440,18 +1437,20 @@ static int loose_object_info(struct repository *r, status = error(_("unable to unpack %s header"), oid_to_hex(oid)); } - - 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) { + if (!parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi)) + /* + * oi->{sizep,typep} are meaningless unless + * parse_loose_header() returns >= 0. + */ + parsed_header = 1; + else + status = error(_("unable to parse %s header"), oid_to_hex(oid)); } + if (!allow_unknown && parsed_header && *oi->typep < 0) + die(_("invalid object type")); - if (status >= 0 && oi->contentp) { + if (parsed_header && oi->contentp) { *oi->contentp = unpack_loose_rest(&stream, hdr, *oi->sizep, oid); if (!*oi->contentp) { @@ -1466,6 +1465,8 @@ static int loose_object_info(struct repository *r, 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; } @@ -2531,6 +2532,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; @@ -2547,12 +2549,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/object-store.h b/object-store.h index 31327a7f6c3..65a8e4dc6a8 100644 --- a/object-store.h +++ b/object-store.h @@ -492,8 +492,17 @@ int for_each_packed_object(each_packed_object_fn, void *, int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz, struct strbuf *hdrbuf); -int parse_loose_header(const char *hdr, struct object_info *oi, - unsigned int flags); + +/** + * 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(). + */ +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); int finalize_object_file(const char *tmpfile, const char *filename); diff --git a/streaming.c b/streaming.c index cb3c3cf6ff6..c3dc241d6a5 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) @@ -235,7 +236,8 @@ static int open_istream_loose(struct git_istream *st, struct repository *r, st->u.loose.hdr, sizeof(st->u.loose.hdr), NULL) < 0) || - (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) { + (parse_loose_header(st->u.loose.hdr, &oi) < 0) || + *type < 0) { git_inflate_end(&st->z); munmap(st->u.loose.mapped, st->u.loose.mapsize); return -1; From patchwork Sat Jul 10 13:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7341DC07E9E for ; Sat, 10 Jul 2021 13:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36322613B9 for ; Sat, 10 Jul 2021 13:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbhGJNkg (ORCPT ); Sat, 10 Jul 2021 09:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbhGJNk2 (ORCPT ); Sat, 10 Jul 2021 09:40:28 -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 61275C0613DD for ; Sat, 10 Jul 2021 06:37:43 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id o22so8073770wms.0 for ; Sat, 10 Jul 2021 06:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0LsBWol6+Hg8fOUR73ix2I7C0wS0aT2ZWxxwIiWuxig=; b=e9vi1gRpGgkojfmfBFelwGz4O961MMAInBXjm1ZvV92tvwWW9oxv7qFuVd2LGuK+tN hfL+QN/6hfT/IthJlN6ggUdmDEQumwDwmdWsHQjz+vYZHOzkx/GqIU3abWawdOA2Wodu DivbXUu6LIpHLLI6soOWYN9c8jkslX0kOpPucNTrfZh939wU75wDCpKR0IaQV99/UThu nZ40fJfYKAL6HDo3xKenV20UtIe3ZfuvlMglxN3AjpiuqiDL+8kTa/6QK8m4pqDtOYnj DkZcuUIVSMJDwbMYGD8zuGSqiBAp/eBf+TZGmmRNFAWyhTa8aQN6JXGmrWK5XWsjm+1G VL7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0LsBWol6+Hg8fOUR73ix2I7C0wS0aT2ZWxxwIiWuxig=; b=VqRaWmtL1/qPvpsiw/Xz7a82giOuI6uchmrhAEX8A7swD4zDCQigtQ3OcbddgKmvLz c/kel0pZF9C9/Y7c90nawRiB2xJjlgBh2uYhDCO1DtpvGMuog0UxPD7xhv5CZ0ZD0HK5 I6A/4Cvjhzj/cMA7Ziypva94zAgwa1ijMcf4vm15iXLT/jLiofc28btW+Dk7cdLOGhrp c8oKymmRtXtJAI8KajpDxlFmYm23ez6FK/owsOgPl7xlE80n5pRedf3Bzzy0ccquF6UA PcD8vDX89Pc5/wIWqkZkjQgsxVnRtnjwSAl77gjunIsbzxx1Ekkvn1xLX3ryPih1tvgk 1uhw== X-Gm-Message-State: AOAM5315qR4+EC45sH9RrbNTySoeqJCsffA5dXs4K5SBWb+Uk/5jjEbz Qh1U5TEyBkjMCzBMlnjX+n4yvAlMSJKBzg== X-Google-Smtp-Source: ABdhPJwdqF+a4/DzzuK6OcRRtx2UYlbWXr/dapbBoRnyEew8BMobbtK+dzc4OZpvKy71ZB9HN0kRtA== X-Received: by 2002:a7b:c949:: with SMTP id i9mr28472988wml.168.1625924261801; Sat, 10 Jul 2021 06:37:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 15/21] object-file.c: guard against future bugs in loose_object_info() Date: Sat, 10 Jul 2021 15:37:18 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org An earlier version of the preceding commit had a subtle bug where our "type_scratch" (later assigned to "oi->typep") would be uninitialized and used in the "!allow_unknown" case, at which point it would contain a nonsensical value if we'd failed to call parse_loose_header(). The preceding commit introduced "parsed_header" variable to check for this case, but I think we can do better, let's carry a "oi_header" variable initially set to NULL, and only set it to "oi" once we're past parse_loose_header(). This is functionally the same thing, but hopefully makes it even more obvious in the future that we must not access the "typep" and "sizep" (or "type_name") unless parse_loose_header() succeeds, but that accessing other fields set earlier (such as the "disk_sizep" set earlier) is OK. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/object-file.c b/object-file.c index 31263335af9..d41f444e6cc 100644 --- a/object-file.c +++ b/object-file.c @@ -1393,7 +1393,7 @@ static int loose_object_info(struct repository *r, struct strbuf hdrbuf = STRBUF_INIT; unsigned long size_scratch; enum object_type type_scratch; - int parsed_header = 0; + struct object_info *oi_header = NULL; int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; if (oi->delta_base_oid) @@ -1441,18 +1441,20 @@ static int loose_object_info(struct repository *r, if (!parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi)) /* * oi->{sizep,typep} are meaningless unless - * parse_loose_header() returns >= 0. + * parse_loose_header() returns >= 0. Let's + * access them as "oi_header" (just an alias + * for "oi") below to make that intent clear. */ - parsed_header = 1; + oi_header = oi; else status = error(_("unable to parse %s header"), oid_to_hex(oid)); } - if (!allow_unknown && parsed_header && *oi->typep < 0) + if (!allow_unknown && oi_header && *oi_header->typep < 0) die(_("invalid object type")); - if (parsed_header && oi->contentp) { + if (oi_header && oi->contentp) { *oi->contentp = unpack_loose_rest(&stream, hdr, - *oi->sizep, oid); + *oi_header->sizep, oid); if (!*oi->contentp) { git_inflate_end(&stream); status = -1; From patchwork Sat Jul 10 13:37:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAD9DC11F67 for ; Sat, 10 Jul 2021 13:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0123613B9 for ; Sat, 10 Jul 2021 13:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbhGJNki (ORCPT ); Sat, 10 Jul 2021 09:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231896AbhGJNk3 (ORCPT ); Sat, 10 Jul 2021 09:40:29 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A58C0613E5 for ; Sat, 10 Jul 2021 06:37:44 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id t5so2645994wrw.12 for ; Sat, 10 Jul 2021 06:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DWlM3thwZepB5bHIEVDk0JIgE9Qo4Yn1JyVgH9wmaDI=; b=amlGe9IpT4YGLt0QhIQQVcE5yoVXZvNeQqXP5sVVhtcK1Wn5P4zrfVtnI0Br9K3owg gId4KANhgvgU9R91AeExX4/hIoiEU5DLTuuqG9Y1/djXug8+BR1TrNEJe3DVYBbGxCM8 gDZua8XGeUQal41kmvM+c0wa7qo33NYfb4IUmkxQf/gFLxIPemHwTdNSYcEsIEwI1WIT gxitCbtnj2Oxr2Zsk5as3Szi8oZdpX1rzTpkNL/SeAvKeoYRbpyVZySmh8LGq6QjI0MZ DOWkLheoaC/anbV8RbnXtV/lUKNSC/2BKr5q7nzr/SSY5AH6X+X+HlgcsYcApgvo/xM0 Bu8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DWlM3thwZepB5bHIEVDk0JIgE9Qo4Yn1JyVgH9wmaDI=; b=fEpLoeDYBZKVEXUNp+vi4jCRwqy9D48DL/Qsc01MWwN8cNUFV8h4BhTJrtEjJekNNv VTrgI1RrKN1tJEb35Nll+dEgq0ddmZ+mTwGrIhRCg+LrABtz/qijXL4NqbZwDwijf+xG y4eIr0ADBHBgj2tNJ4bpAj6BJNwjZAk/DVA/PUl5IlEbKfMIiZG0oanm8zYGpcXYpIWo l7cEvHwh4yIf53VVsz5zlELzJyZJdnTO1P1sJbieHwQUsthsLkB2fuTWRB8bvabbG6I9 8RHTdNdS8x9iZ6H8vE/YWHLgAlQU3nJYRzfXSV1H3ZneKUijB+BU+UOkzlmT1+6KSNZI EwAg== X-Gm-Message-State: AOAM532XXdFW7rM6avnj3ngvU7+ADffgkjkQ8OayYRniC6oQTdUkDPpB H45nHVxSzxBlZgYYloWmi59wYwbyeUpucw== X-Google-Smtp-Source: ABdhPJxVf9NTM+/ux2atXJ4V+JHT1dYoHqNkEMtPxgvUay4hRt+prIPDmWFtqAbkncwUbX33CS73+Q== X-Received: by 2002:a5d:524e:: with SMTP id k14mr12299255wrc.264.1625924262556; Sat, 10 Jul 2021 06:37:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 16/21] object-file.c: return -1, not "status" from unpack_loose_header() Date: Sat, 10 Jul 2021 15:37:19 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 d41f444e6cc..956ca260518 100644 --- a/object-file.c +++ b/object-file.c @@ -1229,7 +1229,7 @@ int unpack_loose_header(git_zstream *stream, status = git_inflate(stream, 0); obj_read_lock(); if (status < Z_OK) - return status; + return -1; /* * Check if entire header is unpacked in the first iteration. From patchwork Sat Jul 10 13:37:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D79E5C11F6E for ; Sat, 10 Jul 2021 13:37:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD3AD613B9 for ; Sat, 10 Jul 2021 13:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbhGJNki (ORCPT ); Sat, 10 Jul 2021 09:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbhGJNkd (ORCPT ); Sat, 10 Jul 2021 09:40:33 -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 141A8C061786 for ; Sat, 10 Jul 2021 06:37:45 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d12so15872629wre.13 for ; Sat, 10 Jul 2021 06:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y2u6VsoElTul7SYGEO8+qocLzqltnHY0SDx6Uasol4M=; b=PU0Rd7XrXryyGBLE2Z/QFqPJj4UkZH9fDGWVucNSWqSS34RWxsg1c9ifuwbqtz/4w1 n6xFhEXdDUHTbuWCOme3K1jo31yO4q+VIOepUr/bhcTHl8Cieb2ehuFFHk1D034ZDD3s gWjh/KbYmsO7KCN0d1aCwguw5x9+ER+VnjRpoLx/M9LQA86JARqq28qZLxmX349x9SxC BjQQYNd0pMsdDTkIM7s0seld/CRZKChHvjXh2RECS7to6rWL8+jpwIzWvG5JH/nYgPYo 3GXOAmG0cp0FyfatWIApHH8ZmQFAc6fWn/LSeLAP7+NnEZ/LgJGmMaUDEtpygrZzxkQV 3m/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y2u6VsoElTul7SYGEO8+qocLzqltnHY0SDx6Uasol4M=; b=TbUEmUGWmRAwU2RLe1VWDhpew/pOqwqbCtoftQEpMVnl3CsY3xJsif0PdElC8QsbkK zOkqgVMXZ++G7rILohctsUnb0qfA4wjWx7EyknRRUDUi+BoUKsUaxsGew3J9U7agryEw XH2j/xKfPdlUJL/9wrjPPDEeA3TfBPcZJwvn5lroZOuXm5s2vOh3IvIIWS5+al/6TMuN qWrHKdyXBV+tlyqh/P1N8yCSGuibAxMruUDyyFURVRUvMSU7T79AM4tgdleTC5KQQ75f 3mEWWlXYdV5wNxc5uSYl0w1nAzkaDERMvvk4/OkvTaVrkFpjk7l3F4j6r0YjCcsJNewa Lr/Q== X-Gm-Message-State: AOAM532e4ebziGfNDbjLERCNcUSqXAWWdldF3B55iVrZmJjBLgUp0x6M uIG19767zzVv8w1PQ7G8kAXjUJjMUbLOCA== X-Google-Smtp-Source: ABdhPJwhSr6Fuyq3pp7k9+JXb9PjJ3bA8mPUHVw2d7sygXwqyyiAHYmcvGmK0LvHe73GvDa+uO6tFA== X-Received: by 2002:a5d:4351:: with SMTP id u17mr47210971wrr.47.1625924263317; Sat, 10 Jul 2021 06:37:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 17/21] object-file.c: return -2 on "header too long" in unpack_loose_header() Date: Sat, 10 Jul 2021 15:37:20 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 -2 saying we ran into the MAX_HEADER_LEN limit, or other negative values for "unable to unpack header". I tried setting up an enum just for these three return values, but I think the result was less readable. Let's consider doing that if we gain even more return values. For now let's do the next best thing and enumerate our known return values, and BUG() if we encounter one we don't know about. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 16 +++++++++++++--- object-store.h | 6 ++++-- t/t1006-cat-file.sh | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/object-file.c b/object-file.c index 956ca260518..1866115a1c5 100644 --- a/object-file.c +++ b/object-file.c @@ -1243,7 +1243,7 @@ int unpack_loose_header(git_zstream *stream, * --allow-unknown-type". */ if (!header) - return -1; + return -2; /* * buffer[0..bufsiz] was not large enough. Copy the partial @@ -1264,7 +1264,7 @@ int unpack_loose_header(git_zstream *stream, stream->next_out = buffer; stream->avail_out = bufsiz; } while (status != Z_STREAM_END); - return -1; + return -2; } static void *unpack_loose_rest(git_zstream *stream, @@ -1433,9 +1433,19 @@ static int loose_object_info(struct repository *r, hdr_ret = unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), allow_unknown ? &hdrbuf : NULL); - if (hdr_ret < 0) { + switch (hdr_ret) { + case 0: + break; + case -1: status = error(_("unable to unpack %s header"), oid_to_hex(oid)); + break; + case -2: + status = error(_("header for %s too long, exceeds %d bytes"), + oid_to_hex(oid), MAX_HEADER_LEN); + break; + default: + BUG("unknown hdr_ret value %d", hdr_ret); } if (!status) { if (!parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi)) diff --git a/object-store.h b/object-store.h index 65a8e4dc6a8..1151ce8e820 100644 --- a/object-store.h +++ b/object-store.h @@ -481,13 +481,15 @@ int for_each_packed_object(each_packed_object_fn, void *, * unpack_loose_header() initializes the data stream needed to unpack * a loose object header. * - * Returns 0 on success. Returns negative values on error. + * Returns 0 on success. Returns negative values on error. If the + * header exceeds MAX_HEADER_LEN -2 will be returned. * * 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(), -2 will still be returned from this + * function to indicate that the header was too long. */ int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 86fd2a90ca7..06d38e1fae6 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -440,7 +440,7 @@ bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_t test_expect_success 'die on broken object with large type under -t and -s without --allow-unknown-type' ' cat >err.expect <<-EOF && - error: unable to unpack $bogus_sha1 header + error: header for $bogus_sha1 too long, exceeds 32 bytes fatal: git cat-file: could not get object info EOF From patchwork Sat Jul 10 13:37:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D03E8C11F6D for ; Sat, 10 Jul 2021 13:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E8AC613BE for ; Sat, 10 Jul 2021 13:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232467AbhGJNkj (ORCPT ); Sat, 10 Jul 2021 09:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232363AbhGJNkd (ORCPT ); Sat, 10 Jul 2021 09:40:33 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C83C061788 for ; Sat, 10 Jul 2021 06:37:46 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id k32so4813658wms.4 for ; Sat, 10 Jul 2021 06:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dOlj0VIhYc2eslc6e65RLV/1lb9wBeTcaTVfptaSi10=; b=SJlyNbbfGcCl5Ahp+8xXg6ZNOjtb5lv7LaGbFzmyf+6wUNViYrkixNRDyIauud4Kv0 0DBprThzpVWMm89UIhdIpQKuLNftcsYIyzVnMyUqu9kqqvAARyN6ExC2nKYXxPZbLpSB 8nGkWKp09faz9OHr7GrPL3mp47Janu3ULFbu/tQZYGiT4nCk0e0Lcgj3Qc/2pEwley1f ffiADU208aFnfcD+jSfXKOWdlb+NCEgyJ90amfdFg9hsqSh4aQ1TaSaDasapbPsMKU0F xJ9u21poUJY8Ukm03KRL8wOlv/OEOV+4uafaaxxspnHkOkfJ9i44HXJllMfLukGwBX9A Budw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dOlj0VIhYc2eslc6e65RLV/1lb9wBeTcaTVfptaSi10=; b=WBYQKnHjFynBoK976pVnpB/sA/F/1L4zsEmiC830RRtJVfEVPGAOFChUBCuxK0Eul6 Lu/RgtzHt3/akWbdnuE69G7Mg0br+AdZm09QvWQjeTVDn600Y+RKJ1wZwXYATYJQlOhc K78iErb/jswDEuAJqjuspcf6qwMN6Oo9EC9GJA75ivjbfv5T9SNfjAcaMqzmjBPwybYB zUU237idZvAYmcT9DqFaM9R4pV/66BP1RBboY/tO/4CxmRY7wpS0q6fQHVRLC8Hz5ZBF NYCYs6uJbTNOVEllm5a4yixWJ/M3HIHdow4/vbh8/U0B6MbseitRUddZuYn/awfnGvg5 285g== X-Gm-Message-State: AOAM531rttKzlk2WSfT/GLtlcCEfAXEN+T4cFtH+9TlUY2Sbj0U9faYS xoBtrf/bTrJjtj3P7MU9WAMiLjAXYjl6jw== X-Google-Smtp-Source: ABdhPJwTwRmxL/s39NT5m3tDyGwt02pKIDDIY1TTQEO6MZazn/tLncyBKx8bC3rdEysaov7iQhk2TA== X-Received: by 2002:a1c:3505:: with SMTP id c5mr4482342wma.53.1625924264188; Sat, 10 Jul 2021 06:37:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 18/21] fsck: don't hard die on invalid object types Date: Sat, 10 Jul 2021 15:37:21 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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: hash mismatch for (expected ) error: : object corrupt or missing: [ the rest of the fsck output here, i.e. it didn't hard die ] 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. See f6371f92104 (sha1_file: add read_loose_object() function, 2017-01-13) for the introduction of read_loose_object(). Why are we complaining about a "hash mismatch" for an object of a type we don't know about? We shouldn't. This is the bare minimal change needed to not make fsck hard die on a repository that's been corrupted in this manner. In subsequent commits we'll teach fsck to recognize this particular type of corruption and emit a better error message. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 3 ++- object-file.c | 11 ++++++++--- object-store.h | 3 ++- t/t1450-fsck.sh | 14 +++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index b42b6fe21f7..082dadd5629 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -601,7 +601,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) void *contents; int eaten; - if (read_loose_object(path, oid, &type, &size, &contents) < 0) { + if (read_loose_object(path, oid, &type, &size, &contents, + OBJECT_INFO_ALLOW_UNKNOWN_TYPE) < 0) { errors_found |= ERROR_OBJECT; error(_("%s: object corrupt or missing: %s"), oid_to_hex(oid), path); diff --git a/object-file.c b/object-file.c index 1866115a1c5..8fb55fc6f58 100644 --- a/object-file.c +++ b/object-file.c @@ -2536,7 +2536,8 @@ int read_loose_object(const char *path, const struct object_id *expected_oid, enum object_type *type, unsigned long *size, - void **contents) + void **contents, + unsigned int oi_flags) { int ret = -1; void *map = NULL; @@ -2544,6 +2545,7 @@ int read_loose_object(const char *path, git_zstream stream; char hdr[MAX_HEADER_LEN]; struct object_info oi = OBJECT_INFO_INIT; + int allow_unknown = oi_flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; oi.typep = type; oi.sizep = size; @@ -2566,8 +2568,11 @@ int read_loose_object(const char *path, git_inflate_end(&stream); goto out; } - if (*type < 0) - die(_("invalid object type")); + if (!allow_unknown && *type < 0) { + error(_("header for %s declares an unknown type"), path); + git_inflate_end(&stream); + goto out; + } if (*type == OBJ_BLOB && *size > big_file_threshold) { if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0) diff --git a/object-store.h b/object-store.h index 1151ce8e820..94ff03072c1 100644 --- a/object-store.h +++ b/object-store.h @@ -245,7 +245,8 @@ int read_loose_object(const char *path, const struct object_id *expected_oid, enum object_type *type, unsigned long *size, - void **contents); + void **contents, + unsigned int oi_flags); /* 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 f10d6f7b7e8..d8303db9709 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -863,16 +863,16 @@ 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 && empty_blob=$(git -C garbage-type hash-object --stdin -w -t blob err.expect <<-\EOF && - fatal: invalid object type - EOF - test_must_fail git -C garbage-type fsck >out.actual 2>err.actual && - test_cmp err.expect err.actual && - test_must_be_empty out.actual + test_must_fail git -C garbage-type fsck >out 2>err && + grep -e "^error" -e "^fatal" err >errors && + test_line_count = 2 errors && + grep "error: hash mismatch for" err && + grep "$garbage_blob: object corrupt or missing:" err && + grep "dangling blob $empty_blob" out ' test_done From patchwork Sat Jul 10 13:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12368635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5621EC11F6F for ; Sat, 10 Jul 2021 13:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 128BE613BE for ; Sat, 10 Jul 2021 13:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231727AbhGJNkj (ORCPT ); Sat, 10 Jul 2021 09:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbhGJNkd (ORCPT ); Sat, 10 Jul 2021 09:40:33 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEAA4C06178A for ; Sat, 10 Jul 2021 06:37:46 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d12so15872712wre.13 for ; Sat, 10 Jul 2021 06:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=96if8fanmUd+XYMGydTnLu0UhpqNW1O/ECyN0bL+AgA=; b=dD4x4szmSumxSDWKM3U7nWPVfLBGt3vD/A5bKGCjI8LQyDSor9Vs9EA7eaRW+J/HdU QOY9IQxg7SXeNRxDdKcbxQV1WhR1KVLgSPlmGMvK2VwbRmkvD2jFfPzG8nKi919flOmi tBhoOLyg/Vb7/GI4mCRwMSslT3T+7DoCxE2dNEl+UlJQcaBjXCITuwLhMjgmVqEBWfZi dU5zz+Vl1ezRYFFxCbsXXBr1j/zMzU/50X76uQsSl8UZ5L+/Xw8G1uaMVpwm9/P3dEyw ncPJCOWN6NqijLmpPtHktA2Vco5H6ZtAKfD7TygVwCH28R86N6Ll2bIThD1/zgdTI3rE klsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=96if8fanmUd+XYMGydTnLu0UhpqNW1O/ECyN0bL+AgA=; b=lWfN0FFw+dCSoE8gxKYb5h0LSei09HJ2jhhPqXHJ8TJGYeFF7p2Wve/hqHID6yVrlx t992bS+np1KVgH1ymcgyADhBr8fbSeAOuV7mwC00FX5dTBAmeS3HZGEQflAL9UFHfRVo 2ROHErGkHusNE7XC9N9yXmwL1MqjlsdQyebugg/N7mRQqf3mLURCiTziMJnQhtTwBhhE kGywUUSWnbrz9sZ+H5GbAKvEzroolDuoIuGYKvQu3G9PNh9rVHhrCvNhBvMUoQW7wMlH 5cDbpll2FoVttLw84P/VHe/uc1R+pxAGJqmqx+Xe/RuPKQb0B10TVZrx37bxURnLN9Rk C68A== X-Gm-Message-State: AOAM532JFOR5MfDC2zawWymY3ODe+03CiNxkbi2U37PXb5goO2TFE8uL zqhxdw4Hxc3jfCJOF1wnMil6a9v/kgk6dg== X-Google-Smtp-Source: ABdhPJxHINJgg++leZEvcouXOs7sLRhF2G5+zK+ekdp7UasPFEFS6fhpBiSPEVk/l3AnusOQ9buACw== X-Received: by 2002:a5d:6dd2:: with SMTP id d18mr48529890wrz.94.1625924265100; Sat, 10 Jul 2021 06:37:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 19/21] object-store.h: move read_loose_object() below 'struct object_info' Date: Sat, 10 Jul 2021 15:37:22 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the declaration of read_loose_object() below "struct object_info". In the next commit we'll add a "struct object_info *" parameter to it, moving it will avoid a forward declaration of the struct. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-store.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/object-store.h b/object-store.h index 94ff03072c1..72d668b1674 100644 --- a/object-store.h +++ b/object-store.h @@ -234,20 +234,6 @@ int pretend_object_file(void *, unsigned long, enum object_type, 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, - * type, and size. If the object is a blob, then "contents" may return NULL, - * to allow streaming of large blobs. - * - * Returns 0 on success, negative on error (details may be written to stderr). - */ -int read_loose_object(const char *path, - const struct object_id *expected_oid, - enum object_type *type, - unsigned long *size, - void **contents, - unsigned int oi_flags); - /* Retry packed storage after checking packed and loose storage */ #define HAS_OBJECT_RECHECK_PACKED 1 @@ -388,6 +374,20 @@ int oid_object_info_extended(struct repository *r, const struct object_id *, struct object_info *, unsigned flags); +/* + * Open the loose object at path, check its hash, and return the contents, + * type, and size. If the object is a blob, then "contents" may return NULL, + * to allow streaming of large blobs. + * + * Returns 0 on success, negative on error (details may be written to stderr). + */ +int read_loose_object(const char *path, + const struct object_id *expected_oid, + enum object_type *type, + unsigned long *size, + void **contents, + unsigned int oi_flags); + /* * Iterate over the files in the loose-object parts of the object * directory "path", triggering the following callbacks: From patchwork Sat Jul 10 13:37:23 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: 12368639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7613CC11F66 for ; Sat, 10 Jul 2021 13:37:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D12A613B9 for ; Sat, 10 Jul 2021 13:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbhGJNkk (ORCPT ); Sat, 10 Jul 2021 09:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232413AbhGJNkd (ORCPT ); Sat, 10 Jul 2021 09:40:33 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8812FC0613DD for ; Sat, 10 Jul 2021 06:37:47 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso10861725wmh.4 for ; Sat, 10 Jul 2021 06:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sw4TNfVARROgBMNypcWydDFz9GLH3Cvnn+oUPRUVvQM=; b=j6JL8TrNbJlUJkahfvPNA1wVwx/PqNfVjcHF+UwJ5cCbT3amuReAnAIxBDK5qzwZjZ UiJlUY11MX5TRrfQJXH0nIMzneTq4lO20DZfeUHyXUD+GjYcyNcIfj5aA5gKx1v6z4lh RsE9xXmMeiUykhRQG+1xUgtCrfqnBOjdRqEI8hcW+BV9nqDLNK9IawK+uGy4AE9n2lQS SE9VhwG5fsTGkupGAkv0Eh8Ce9pMTyb0VTgCzuwI4rDmEwfG1IjpWxtGAOwzGWyUrGQv /l07TyFcwKC83SR52YR9B05b5371WihcACvzbDNOqwtYyym0Igh9LRqsI6ATiDJ52ihJ Ruxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sw4TNfVARROgBMNypcWydDFz9GLH3Cvnn+oUPRUVvQM=; b=jGBkF0b/Dy0q5arl/CQsf2BkNPa/d6alecYVam+1tVws6d9H0csVxBfI8M5u0e9zVT iCtHubgKQm1c41I4G4BJEkOQayrSUP12d9Z3PEk0i/DlSOMbqHWv7YuY58AA7goVnfIq ui3p0xNpvh6uZZqz53+uobXXRYsJliSKRMxe2YNR4STlFH+v7Zd63TWdzWrV+KqrtfeO hx4qKKC40HfTEgyM8rMrRlXaJNu7pugiZDgxU+xQ9gAXzbOtEBhK8ZVypAzd9pVKG0YV IojKRN1duLNKgR43OA35jtXCDXYNgFvk7YM+1esVPUC60Zei+iSllnhbb255Sl8P+7Qh yhUA== X-Gm-Message-State: AOAM533fanrG9z5A1VoXYL3VSHKu3qSuUjkxnDOcxmn5UsmA2qiItzHa mJJs5ttRyAGYsFXO8OPKa5lhYqNQ5oNF+A== X-Google-Smtp-Source: ABdhPJxOopYAKsIkxOv3AtrIC2saVTvgtYCe6V+bVQonm1uLdHUJ15yyhFZ0byKANaucGeCu/E0M/g== X-Received: by 2002:a7b:c193:: with SMTP id y19mr4625735wmi.86.1625924265918; Sat, 10 Jul 2021 06:37:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 20/21] fsck: report invalid types recorded in objects Date: Sat, 10 Jul 2021 15:37:23 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the work in the preceding commit and improve the error on: $ git hash-object --stdin -w -t garbage --literally (expected ) error: : object corrupt or missing: [ other fsck output ] To instead emit: $ git fsck error: : object is of unknown type 'garbage': [ other fsck output ] The complaint about a "hash mismatch" was simply an emergent property of how we'd fall though from read_loose_object() into fsck_loose() when we didn't get the data we expected. Now we'll correctly note that the object type is invalid. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 22 ++++++++++++++++++---- object-file.c | 13 +++++-------- object-store.h | 4 ++-- t/t1450-fsck.sh | 24 +++++++++++++++++++++--- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 082dadd5629..07af0434db6 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -600,12 +600,26 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) unsigned long size; void *contents; int eaten; - - if (read_loose_object(path, oid, &type, &size, &contents, - OBJECT_INFO_ALLOW_UNKNOWN_TYPE) < 0) { - errors_found |= ERROR_OBJECT; + struct strbuf sb = STRBUF_INIT; + unsigned int oi_flags = OBJECT_INFO_ALLOW_UNKNOWN_TYPE; + struct object_info oi; + int found = 0; + oi.type_name = &sb; + oi.sizep = &size; + oi.typep = &type; + + if (read_loose_object(path, oid, &contents, &oi, oi_flags) < 0) { + found |= ERROR_OBJECT; error(_("%s: object corrupt or missing: %s"), oid_to_hex(oid), path); + } + if (type < 0) { + found |= ERROR_OBJECT; + error(_("%s: object is of unknown type '%s': %s"), + oid_to_hex(oid), sb.buf, path); + } + if (found) { + errors_found |= ERROR_OBJECT; return 0; /* keep checking other objects */ } diff --git a/object-file.c b/object-file.c index 8fb55fc6f58..e550ea0c7cf 100644 --- a/object-file.c +++ b/object-file.c @@ -2534,9 +2534,8 @@ 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, + struct object_info *oi, unsigned int oi_flags) { int ret = -1; @@ -2544,10 +2543,9 @@ 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; int allow_unknown = oi_flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE; - oi.typep = type; - oi.sizep = size; + enum object_type *type = oi->typep; + unsigned long *size = oi->sizep; *contents = NULL; @@ -2563,7 +2561,7 @@ 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; @@ -2585,8 +2583,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 72d668b1674..96a5970f314 100644 --- a/object-store.h +++ b/object-store.h @@ -376,6 +376,7 @@ int oid_object_info_extended(struct repository *r, /* * 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. * @@ -383,9 +384,8 @@ int oid_object_info_extended(struct repository *r, */ int read_loose_object(const char *path, const struct object_id *expected_oid, - enum object_type *type, - unsigned long *size, void **contents, + struct object_info *oi, unsigned int oi_flags); /* diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index d8303db9709..da2658155c7 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -66,6 +66,25 @@ 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 && + test_must_fail git fsck 2>out && + grep "^error: hash mismatch for " out && + grep "^error: $oid: object is of unknown type '"'"'garbage'"'"'" out + ) +' + 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" && @@ -869,9 +888,8 @@ test_expect_success 'fsck error and recovery on invalid object type' ' garbage_blob=$(git -C garbage-type hash-object --stdin -w -t garbage --literally out 2>err && grep -e "^error" -e "^fatal" err >errors && - test_line_count = 2 errors && - grep "error: hash mismatch for" err && - grep "$garbage_blob: object corrupt or missing:" err && + test_line_count = 1 errors && + grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err && grep "dangling blob $empty_blob" out ' From patchwork Sat Jul 10 13:37:24 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: 12368647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D245AC11F72 for ; Sat, 10 Jul 2021 13:37:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC2E8613B9 for ; Sat, 10 Jul 2021 13:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232466AbhGJNkm (ORCPT ); Sat, 10 Jul 2021 09:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232084AbhGJNkf (ORCPT ); Sat, 10 Jul 2021 09:40:35 -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 85A1BC0617A6 for ; Sat, 10 Jul 2021 06:37:48 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id g16so6586978wrw.5 for ; Sat, 10 Jul 2021 06:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mb45U6LEYqhRA0P7UG/OHRgCMxdF9YwCAOsIPA3NAys=; b=rE+rPArGo1SwQF4MdvI/ac6/RmzOl8z/8XY1otWjEnwZJ3SgJzqucw33jLgTevd4Sw Mg/KjUjwmo10U9Wh48GeLwYP/Cs2PZv7MAvU8jgM66MObfl2lHJLGBHDaAnRcvxCZyjU N0oBv8k1/yeiAJxIw+dMN+bwbWyTBRD1FXlpTNk4+FlV5MVf4Nn6LXZQZdUILRRe697u lvfX4m3ic614mBTfqtDoIHDjWGdyw2aGYCAH1iAgOBJHmzM3Pb2pR16pi+Luzj+8sZR0 Pdo9pXX5Ow2EAPdFLoPk4BkhfMqjbqRlfIEijVSNNJ1bc1oH/rk6PUSvFvwZIVZb0KWI PZOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mb45U6LEYqhRA0P7UG/OHRgCMxdF9YwCAOsIPA3NAys=; b=WXVTP0IimmZDC2DlgyByamw3JHGHlb2+H7kZdvxhpdp6kvBaHPDze49WDYHIfyM/a3 Sj9JKA51o9/alkaIXHRAwpowyZZxClTzClvE+gswsg08gdq99A+srFZqWXH2j1H0MINp YvMbvz8NzB7aDyjk2jlPMHhlW3VkYAO5xCC/9vpqqlp53e5WxIF5PbpT3mwrQPiYXbjK EiFd9Pk+ljJkyPp+UeCkxUn1rzhx4rdsZUCmuaYKEwE+fQAb05qFsLSMpBPt/Fa6Qm0z pe/ULAw9A9SxAlZlYF5iSdLA3r7K6czqu6eIOzhvHI4GqNSWQ8vlx9VeNeHVIQ3JmtpW U21g== X-Gm-Message-State: AOAM5332bpwiUKkkQyhPPYNSRopU6ftuEgReOWpYoZRjBKgGbgF7SrPa bQMXVlWQ3O/cVRkImNdHEmjIkEExb8lVSA== X-Google-Smtp-Source: ABdhPJw8AsIcnWEzIpogDQQUIS2Q56rbMgoqY60Ek0SyZM1U1UB2sNe4WhWVaZ0FZYfvFfL/gqeoBQ== X-Received: by 2002:a5d:4449:: with SMTP id x9mr22422210wrr.52.1625924266806; Sat, 10 Jul 2021 06:37:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j17sm17612787wmq.9.2021.07.10.06.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jul 2021 06:37:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Jonathan Tan , Felipe Contreras , Andrei Rybak , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 21/21] fsck: report invalid object type-path combinations Date: Sat, 10 Jul 2021 15:37:24 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.636.g43e71d69cff 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 --- builtin/fast-export.c | 2 +- builtin/fsck.c | 13 +++++++++---- builtin/index-pack.c | 2 +- builtin/mktag.c | 3 ++- object-file.c | 21 ++++++++++++--------- object-store.h | 4 +++- object.c | 4 ++-- pack-check.c | 3 ++- t/t1006-cat-file.sh | 2 +- t/t1450-fsck.sh | 8 +++++--- 10 files changed, 38 insertions(+), 24 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 3c20f164f0f..48a3b6a7f8f 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 07af0434db6..158b9dac9b3 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -603,20 +603,25 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) struct strbuf sb = STRBUF_INIT; unsigned int oi_flags = OBJECT_INFO_ALLOW_UNKNOWN_TYPE; struct object_info oi; + struct object_id real_oid = *null_oid(); int found = 0; oi.type_name = &sb; oi.sizep = &size; oi.typep = &type; - if (read_loose_object(path, oid, &contents, &oi, oi_flags) < 0) { + if (read_loose_object(path, oid, &real_oid, &contents, &oi, oi_flags) < 0) { found |= ERROR_OBJECT; - error(_("%s: object corrupt or missing: %s"), - oid_to_hex(oid), path); + if (!oideq(&real_oid, oid)) + error(_("%s: hash-path mismatch, found at: %s"), + oid_to_hex(&real_oid), path); + else + error(_("%s: object corrupt or missing: %s"), + oid_to_hex(oid), path); } if (type < 0) { found |= ERROR_OBJECT; error(_("%s: object is of unknown type '%s': %s"), - oid_to_hex(oid), sb.buf, path); + oid_to_hex(&real_oid), sb.buf, path); } if (found) { errors_found |= ERROR_OBJECT; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 3fbc5d70777..bf860b6555e 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1421,7 +1421,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/object-file.c b/object-file.c index e550ea0c7cf..923ff759e19 100644 --- a/object-file.c +++ b/object-file.c @@ -1039,9 +1039,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; @@ -1049,8 +1051,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); @@ -1075,9 +1077,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) @@ -2534,6 +2536,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, unsigned int oi_flags) @@ -2583,9 +2586,9 @@ 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)) { + if (oideq(real_oid, null_oid())) + BUG("should only get OID mismatch errors with mapped contents"); free(*contents); goto out; } diff --git a/object-store.h b/object-store.h index 96a5970f314..9fc69016361 100644 --- a/object-store.h +++ b/object-store.h @@ -384,6 +384,7 @@ int oid_object_info_extended(struct repository *r, */ int read_loose_object(const char *path, const struct object_id *expected_oid, + struct object_id *real_oid, void **contents, struct object_info *oi, unsigned int oi_flags); @@ -507,7 +508,8 @@ int unpack_loose_header(git_zstream *stream, unsigned char *map, 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); int check_and_freshen_file(const char *fn, int freshen); diff --git a/object.c b/object.c index 14188453c56..5467ead3285 100644 --- a/object.c +++ b/object.c @@ -261,7 +261,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; } @@ -272,7 +272,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 4b089fe8ec0..e6aa4442c90 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 06d38e1fae6..72386cfec0e 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -490,7 +490,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 da2658155c7..7d0d57564b5 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -53,6 +53,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)" && @@ -62,7 +63,7 @@ test_expect_success 'object with hash mismatch' ' cmt=$(echo bogus | git commit-tree $tree) && git update-ref refs/heads/bogus $cmt && test_must_fail git fsck 2>out && - test_i18ngrep "$oid.*corrupt" out + grep "$oldoid: hash-path mismatch, found at: .*$new" out ) ' @@ -71,6 +72,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)" && @@ -80,8 +82,8 @@ test_expect_success 'object with hash and type mismatch' ' cmt=$(echo bogus | git commit-tree $tree) && git update-ref refs/heads/bogus $cmt && 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 ) '