Skip to content

Commit 55c5648

Browse files
derrickstoleegitster
authored andcommitted
multi-pack-index: verify oid lookup order
Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f23d3f commit 55c5648

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

midx.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,5 +959,16 @@ int verify_midx_file(const char *object_dir)
959959
i, oid_fanout1, oid_fanout2, i + 1);
960960
}
961961

962+
for (i = 0; i < m->num_objects - 1; i++) {
963+
struct object_id oid1, oid2;
964+
965+
nth_midxed_object_oid(&oid1, m, i);
966+
nth_midxed_object_oid(&oid2, m, i + 1);
967+
968+
if (oidcmp(&oid1, &oid2) >= 0)
969+
midx_report(_("oid lookup out of order: oid[%d] = %s >= %s = oid[%d]"),
970+
i, oid_to_hex(&oid1), oid_to_hex(&oid2), i + 1);
971+
}
972+
962973
return verify_midx_error;
963974
}

t/t5319-multi-pack-index.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ test_expect_success 'verify bad signature' '
175175
"multi-pack-index signature"
176176
'
177177

178+
HASH_LEN=20
178179
MIDX_BYTE_VERSION=4
179180
MIDX_BYTE_OID_VERSION=5
180181
MIDX_BYTE_CHUNK_COUNT=6
@@ -189,6 +190,8 @@ MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
189190
MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + 652))
190191
MIDX_OID_FANOUT_WIDTH=4
191192
MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + 1))
193+
MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
194+
MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
192195

193196
test_expect_success 'verify bad version' '
194197
corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
@@ -235,6 +238,11 @@ test_expect_success 'verify oid fanout out of order' '
235238
"oid fanout out of order"
236239
'
237240

241+
test_expect_success 'verify oid lookup out of order' '
242+
corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
243+
"oid lookup out of order"
244+
'
245+
238246
test_expect_success 'repack removes multi-pack-index' '
239247
test_path_is_file $objdir/pack/multi-pack-index &&
240248
git repack -adf &&

0 commit comments

Comments
 (0)