@@ -51,7 +51,7 @@ do_corrupt_object() {
5151 ofs=` git show-index < ${pack} .idx | grep $1 | cut -f1 -d" " ` &&
5252 ofs=$(( $ofs + $2 )) &&
5353 chmod +w ${pack} .pack &&
54- dd of=${pack} .pack count=1 bs=1 conv=notrunc seek=$ofs &&
54+ dd of=${pack} .pack bs=1 conv=notrunc seek=$ofs &&
5555 test_must_fail git verify-pack ${pack} .pack
5656}
5757
@@ -275,6 +275,33 @@ test_expect_success \
275275 git cat-file blob $blob_2 > /dev/null &&
276276 git cat-file blob $blob_3 > /dev/null'
277277
278+ test_expect_success \
279+ ' corruption of delta base reference pointing to wrong object' \
280+ ' create_new_pack --delta-base-offset &&
281+ git prune-packed &&
282+ printf "\220\033" | do_corrupt_object $blob_3 2 &&
283+ git cat-file blob $blob_1 >/dev/null &&
284+ git cat-file blob $blob_2 >/dev/null &&
285+ test_must_fail git cat-file blob $blob_3 >/dev/null'
286+
287+ test_expect_success \
288+ ' ... but having a loose copy allows for full recovery' \
289+ ' mv ${pack}.idx tmp &&
290+ git hash-object -t blob -w file_3 &&
291+ mv tmp ${pack}.idx &&
292+ git cat-file blob $blob_1 > /dev/null &&
293+ git cat-file blob $blob_2 > /dev/null &&
294+ git cat-file blob $blob_3 > /dev/null'
295+
296+ test_expect_success \
297+ ' ... and then a repack "clears" the corruption' \
298+ ' do_repack --delta-base-offset --no-reuse-delta &&
299+ git prune-packed &&
300+ git verify-pack ${pack}.pack &&
301+ git cat-file blob $blob_1 > /dev/null &&
302+ git cat-file blob $blob_2 > /dev/null &&
303+ git cat-file blob $blob_3 > /dev/null'
304+
278305test_expect_success \
279306 ' corrupting header to have too small output buffer fails unpack' \
280307 ' create_new_pack &&
0 commit comments