aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin/fsck.c10
-rw-r--r--pack-bitmap.c4
-rw-r--r--pack-revindex.c5
-rw-r--r--pack-revindex.h8
-rwxr-xr-xt/t5325-reverse-index.sh15
5 files changed, 36 insertions, 6 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 2ab78129bd..2414190c04 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -872,8 +872,14 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
}
for (struct packed_git *p = get_all_packs(the_repository); p; p = p->next) {
- if (!load_pack_revindex(the_repository, p) &&
- verify_pack_revindex(p)) {
+ int load_error = load_pack_revindex_from_disk(p);
+
+ if (load_error < 0) {
+ error(_("unable to load rev-index for pack '%s'"), p->pack_name);
+ res = ERROR_PACK_REV_INDEX;
+ } else if (!load_error &&
+ !load_pack_revindex(the_repository, p) &&
+ verify_pack_revindex(p)) {
error(_("invalid rev-index for pack '%s'"), p->pack_name);
res = ERROR_PACK_REV_INDEX;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 38b35c4823..3828aab612 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -379,7 +379,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
goto cleanup;
}
- if (load_midx_revindex(bitmap_git->midx) < 0) {
+ if (load_midx_revindex(bitmap_git->midx)) {
warning(_("multi-pack bitmap is missing required reverse index"));
goto cleanup;
}
@@ -2140,7 +2140,7 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
if (!bitmap_is_midx(bitmap_git))
load_reverse_index(r, bitmap_git);
- else if (load_midx_revindex(bitmap_git->midx) < 0)
+ else if (load_midx_revindex(bitmap_git->midx))
BUG("rebuild_existing_bitmaps: missing required rev-cache "
"extension");
diff --git a/pack-revindex.c b/pack-revindex.c
index 62a9846470..146334e2c9 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -212,7 +212,8 @@ static int load_revindex_from_disk(char *revindex_name,
fd = git_open(revindex_name);
if (fd < 0) {
- ret = -1;
+ /* "No file" means return 1. */
+ ret = 1;
goto cleanup;
}
if (fstat(fd, &st)) {
@@ -264,7 +265,7 @@ cleanup:
return ret;
}
-static int load_pack_revindex_from_disk(struct packed_git *p)
+int load_pack_revindex_from_disk(struct packed_git *p)
{
char *revindex_name;
int ret;
diff --git a/pack-revindex.h b/pack-revindex.h
index c8861873b0..6dd47efea1 100644
--- a/pack-revindex.h
+++ b/pack-revindex.h
@@ -52,6 +52,14 @@ struct repository;
int load_pack_revindex(struct repository *r, struct packed_git *p);
/*
+ * Specifically load a pack revindex from disk.
+ *
+ * Returns 0 on success, 1 on "no .rev file", and -1 when there is an
+ * error parsing the .rev file.
+ */
+int load_pack_revindex_from_disk(struct packed_git *p);
+
+/*
* verify_pack_revindex verifies that the on-disk rev-index for the given
* pack-file is the same that would be created if written from scratch.
*
diff --git a/t/t5325-reverse-index.sh b/t/t5325-reverse-index.sh
index 5c3c80f88f..431a603ca0 100755
--- a/t/t5325-reverse-index.sh
+++ b/t/t5325-reverse-index.sh
@@ -190,4 +190,19 @@ test_expect_success 'fsck catches invalid row position' '
"invalid rev-index position"
'
+test_expect_success 'fsck catches invalid header: magic number' '
+ corrupt_rev_and_verify 1 "\07" \
+ "reverse-index file .* has unknown signature"
+'
+
+test_expect_success 'fsck catches invalid header: version' '
+ corrupt_rev_and_verify 7 "\02" \
+ "reverse-index file .* has unsupported version"
+'
+
+test_expect_success 'fsck catches invalid header: hash function' '
+ corrupt_rev_and_verify 11 "\03" \
+ "reverse-index file .* has unsupported hash id"
+'
+
test_done