From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: avarab@gmail.com, Junio C Hamano <gitster@pobox.com>,
Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH 02/11] multi-pack-index: verify bad header
Date: Wed, 05 Sep 2018 07:46:34 -0700 (PDT) [thread overview]
Message-ID: <787e1fb61626afe79cfc846c4175d4b4d169ff42.1536158789.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.34.git.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>
When verifying if a multi-pack-index file is valid, we want the
command to fail to signal an invalid file. Previously, we wrote
an error to stderr and continued as if we had no multi-pack-index.
Now, die() instead of error().
Add tests that check corrupted headers in a few ways:
* Bad signature
* Bad file version
* Bad hash version
* Truncated hash count
* Extended hash count
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
midx.c | 18 +++++----------
t/t5319-multi-pack-index.sh | 46 ++++++++++++++++++++++++++++++++++++-
2 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/midx.c b/midx.c
index b253bed517..ec78254bb6 100644
--- a/midx.c
+++ b/midx.c
@@ -76,24 +76,18 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
m->local = local;
m->signature = get_be32(m->data);
- if (m->signature != MIDX_SIGNATURE) {
- error(_("multi-pack-index signature 0x%08x does not match signature 0x%08x"),
+ if (m->signature != MIDX_SIGNATURE)
+ die(_("multi-pack-index signature 0x%08x does not match signature 0x%08x"),
m->signature, MIDX_SIGNATURE);
- goto cleanup_fail;
- }
m->version = m->data[MIDX_BYTE_FILE_VERSION];
- if (m->version != MIDX_VERSION) {
- error(_("multi-pack-index version %d not recognized"),
+ if (m->version != MIDX_VERSION)
+ die(_("multi-pack-index version %d not recognized"),
m->version);
- goto cleanup_fail;
- }
hash_version = m->data[MIDX_BYTE_HASH_VERSION];
- if (hash_version != MIDX_HASH_VERSION) {
- error(_("hash version %u does not match"), hash_version);
- goto cleanup_fail;
- }
+ if (hash_version != MIDX_HASH_VERSION)
+ die(_("hash version %u does not match"), hash_version);
m->hash_len = MIDX_HASH_LEN;
m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 1c4e0e6d31..836d2bdb53 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -154,6 +154,51 @@ test_expect_success 'verify multi-pack-index success' '
git multi-pack-index verify --object-dir=$objdir
'
+# usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
+corrupt_midx_and_verify() {
+ POS=$1
+ DATA="${2:-\0}"
+ OBJDIR=$3
+ GREPSTR="$4"
+ FILE=$OBJDIR/pack/multi-pack-index &&
+ chmod a+w $FILE &&
+ test_when_finished mv midx-backup $FILE &&
+ cp $FILE midx-backup &&
+ printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
+ test_must_fail git multi-pack-index verify --object-dir=$OBJDIR 2>test_err &&
+ grep -v "^+" test_err >err &&
+ test_i18ngrep "$GREPSTR" err
+}
+
+test_expect_success 'verify bad signature' '
+ corrupt_midx_and_verify 0 "\00" $objdir \
+ "multi-pack-index signature"
+'
+
+MIDX_BYTE_VERSION=4
+MIDX_BYTE_OID_VERSION=5
+MIDX_BYTE_CHUNK_COUNT=6
+
+test_expect_success 'verify bad version' '
+ corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
+ "multi-pack-index version"
+'
+
+test_expect_success 'verify bad OID version' '
+ corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\02" $objdir \
+ "hash version"
+'
+
+test_expect_success 'verify truncated chunk count' '
+ corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
+ "missing required"
+'
+
+test_expect_success 'verify extended chunk count' '
+ corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
+ "terminating multi-pack-index chunk id appears earlier than expected"
+'
+
test_expect_success 'repack removes multi-pack-index' '
test_path_is_file $objdir/pack/multi-pack-index &&
git repack -adf &&
@@ -191,7 +236,6 @@ test_expect_success 'multi-pack-index in an alternate' '
compare_results_with_midx "with alternate (remote midx)"
-
# usage: corrupt_data <file> <pos> [<data>]
corrupt_data () {
file=$1
--
gitgitgadget
next prev parent reply other threads:[~2018-09-05 14:46 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-05 14:46 [PATCH 00/11] Add 'git multi-pack-index verify' command Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 01/11] multi-pack-index: add 'verify' verb Derrick Stolee via GitGitGadget
2018-09-05 18:59 ` Eric Sunshine
2018-09-05 19:37 ` Derrick Stolee
2018-09-05 14:46 ` Derrick Stolee via GitGitGadget [this message]
2018-09-07 0:27 ` [PATCH 02/11] multi-pack-index: verify bad header Eric Sunshine
2018-09-05 14:46 ` [PATCH 03/11] multi-pack-index: verify corrupt chunk lookup table Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 04/11] multi-pack-index: verify packname order Derrick Stolee via GitGitGadget
2018-09-05 18:15 ` Stefan Beller
2018-09-05 19:11 ` Derrick Stolee
2018-09-05 19:14 ` Stefan Beller
2018-09-05 19:28 ` Derrick Stolee
2018-09-05 14:46 ` [PATCH 05/11] multi-pack-index: verify missing pack Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 06/11] multi-pack-index: verify oid fanout order Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 07/11] multi-pack-index: verify oid lookup order Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 08/11] multi-pack-index: fix 32-bit vs 64-bit size check Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 09/11] multi-pack-index: verify object offsets Derrick Stolee via GitGitGadget
2018-09-07 0:34 ` Eric Sunshine
2018-09-07 13:10 ` Derrick Stolee
2018-09-05 14:46 ` [PATCH 10/11] multi-pack-index: report progress during 'verify' Derrick Stolee via GitGitGadget
2018-09-05 14:46 ` [PATCH 11/11] fsck: verify multi-pack-index Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 00/11] Add 'git multi-pack-index verify' command Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 01/11] multi-pack-index: add 'verify' verb Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 02/11] multi-pack-index: verify bad header Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 03/11] multi-pack-index: verify corrupt chunk lookup table Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 04/11] multi-pack-index: verify packname order Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 05/11] multi-pack-index: verify missing pack Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 06/11] multi-pack-index: verify oid fanout order Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 07/11] multi-pack-index: verify oid lookup order Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 08/11] multi-pack-index: fix 32-bit vs 64-bit size check Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 09/11] multi-pack-index: verify object offsets Derrick Stolee via GitGitGadget
2018-09-13 18:02 ` [PATCH v2 10/11] multi-pack-index: report progress during 'verify' Derrick Stolee via GitGitGadget
2018-09-13 19:02 ` Ævar Arnfjörð Bjarmason
2018-09-13 18:02 ` [PATCH v2 11/11] fsck: verify multi-pack-index Derrick Stolee via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=787e1fb61626afe79cfc846c4175d4b4d169ff42.1536158789.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).