Skip to content

Commit 8e72a3c

Browse files
derrickstoleegitster
authored andcommitted
multi-pack-index: verify packname order
The final check we make while loading a multi-pack-index is that the packfile names are in lexicographical order. Make this error be a die() instead. In order to test this condition, we need multiple packfiles. Earlier in t5319-multi-pack-index.sh, we tested the interaction with 'git repack' but this limits us to one packfile in our object dir. Move these repack tests until after the 'verify' tests. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3f8e21 commit 8e72a3c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

midx.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
157157

158158
cur_pack_name += strlen(cur_pack_name) + 1;
159159

160-
if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0) {
161-
error(_("multi-pack-index pack names out of order: '%s' before '%s'"),
160+
if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0)
161+
die(_("multi-pack-index pack names out of order: '%s' before '%s'"),
162162
m->pack_names[i - 1],
163163
m->pack_names[i]);
164-
goto cleanup_fail;
165-
}
166164
}
167165

168166
return m;

t/t5319-multi-pack-index.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ MIDX_BYTE_CHUNK_COUNT=6
181181
MIDX_HEADER_SIZE=12
182182
MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
183183
MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
184+
MIDX_NUM_CHUNKS=5
185+
MIDX_CHUNK_LOOKUP_WIDTH=12
186+
MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
187+
$MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
188+
MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
184189

185190
test_expect_success 'verify bad version' '
186191
corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
@@ -212,6 +217,11 @@ test_expect_success 'verify invalid chunk offset' '
212217
"invalid chunk offset (too large)"
213218
'
214219

220+
test_expect_success 'verify packnames out of order' '
221+
corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
222+
"pack names out of order"
223+
'
224+
215225
test_expect_success 'repack removes multi-pack-index' '
216226
test_path_is_file $objdir/pack/multi-pack-index &&
217227
git repack -adf &&

0 commit comments

Comments
 (0)