Skip to content

Commit 2f23d3f

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

midx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,5 +950,14 @@ int verify_midx_file(const char *object_dir)
950950
midx_report("failed to load pack in position %d", i);
951951
}
952952

953+
for (i = 0; i < 255; i++) {
954+
uint32_t oid_fanout1 = ntohl(m->chunk_oid_fanout[i]);
955+
uint32_t oid_fanout2 = ntohl(m->chunk_oid_fanout[i + 1]);
956+
957+
if (oid_fanout1 > oid_fanout2)
958+
midx_report(_("oid fanout out of order: fanout[%d] = %"PRIx32" > %"PRIx32" = fanout[%d]"),
959+
i, oid_fanout1, oid_fanout2, i + 1);
960+
}
961+
953962
return verify_midx_error;
954963
}

t/t5319-multi-pack-index.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ MIDX_CHUNK_LOOKUP_WIDTH=12
186186
MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
187187
$MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
188188
MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
189+
MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + 652))
190+
MIDX_OID_FANOUT_WIDTH=4
191+
MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + 1))
189192

190193
test_expect_success 'verify bad version' '
191194
corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
@@ -227,6 +230,11 @@ test_expect_success 'verify packnames out of order' '
227230
"failed to load pack"
228231
'
229232

233+
test_expect_success 'verify oid fanout out of order' '
234+
corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
235+
"oid fanout out of order"
236+
'
237+
230238
test_expect_success 'repack removes multi-pack-index' '
231239
test_path_is_file $objdir/pack/multi-pack-index &&
232240
git repack -adf &&

0 commit comments

Comments
 (0)