@@ -51,7 +51,7 @@ do_corrupt_object() {
51
51
ofs=` git show-index < ${pack} .idx | grep $1 | cut -f1 -d" " ` &&
52
52
ofs=$(( $ofs + $2 )) &&
53
53
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 &&
55
55
test_must_fail git verify-pack ${pack} .pack
56
56
}
57
57
@@ -275,6 +275,33 @@ test_expect_success \
275
275
git cat-file blob $blob_2 > /dev/null &&
276
276
git cat-file blob $blob_3 > /dev/null'
277
277
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
+
278
305
test_expect_success \
279
306
' corrupting header to have too small output buffer fails unpack' \
280
307
' create_new_pack &&
0 commit comments