@@ -852,6 +852,44 @@ test_expect_success 'fsck errors in packed objects' '
852852 ! grep corrupt out
853853'
854854
855+ test_expect_success ' fsck handles multiple packfiles with big blobs' '
856+ test_when_finished "rm -rf repo" &&
857+ git init repo &&
858+ (
859+ cd repo &&
860+
861+ # We construct two packfiles with two objects in common and one
862+ # object not in common. The objects in common can then be
863+ # corrupted in one of the packfiles, respectively. The other
864+ # objects that are unique to the packs are merely used to not
865+ # have both packs contain the same data.
866+ blob_one=$(test-tool genrandom one 200k | git hash-object -t blob -w --stdin) &&
867+ blob_two=$(test-tool genrandom two 200k | git hash-object -t blob -w --stdin) &&
868+ blob_three=$(test-tool genrandom three 200k | git hash-object -t blob -w --stdin) &&
869+ blob_four=$(test-tool genrandom four 200k | git hash-object -t blob -w --stdin) &&
870+ pack_one=$(printf "%s\n" "$blob_one" "$blob_two" "$blob_three" | git pack-objects .git/objects/pack/pack) &&
871+ pack_two=$(printf "%s\n" "$blob_two" "$blob_three" "$blob_four" | git pack-objects .git/objects/pack/pack) &&
872+ chmod a+w .git/objects/pack/pack-*.pack &&
873+
874+ # Corrupt blob two in the first pack.
875+ git verify-pack -v .git/objects/pack/pack-$pack_one >objects &&
876+ offset_one=$(sed <objects -n "s/^$blob_two .* \(.*\)$/\1/p") &&
877+ printf "\0" | dd of=.git/objects/pack/pack-$pack_one.pack bs=1 conv=notrunc seek=$offset_one &&
878+
879+ # Corrupt blob three in the second pack.
880+ git verify-pack -v .git/objects/pack/pack-$pack_two >objects &&
881+ offset_two=$(sed <objects -n "s/^$blob_three .* \(.*\)$/\1/p") &&
882+ printf "\0" | dd of=.git/objects/pack/pack-$pack_two.pack bs=1 conv=notrunc seek=$offset_two &&
883+
884+ # We now expect to see two failures for the corrupted objects,
885+ # even though they exist in a non-corrupted form in the
886+ # respective other pack.
887+ test_must_fail git -c core.bigFileThreshold=100k fsck 2>err &&
888+ test_grep "unknown object type 0 at offset $offset_one in .git/objects/pack/pack-$pack_one.pack" err &&
889+ test_grep "unknown object type 0 at offset $offset_two in .git/objects/pack/pack-$pack_two.pack" err
890+ )
891+ '
892+
855893test_expect_success ' fsck fails on corrupt packfile' '
856894 hsh=$(git commit-tree -m mycommit HEAD^{tree}) &&
857895 pack=$(echo $hsh | git pack-objects .git/objects/pack/pack) &&
@@ -918,7 +956,7 @@ test_expect_success 'fsck detects trailing loose garbage (large blob)' '
918956test_expect_success ' fsck detects truncated loose object' '
919957 # make it big enough that we know we will truncate in the data
920958 # portion, not the header
921- test-tool genrandom truncate 4096 >file &&
959+ test-tool genrandom truncate 4k >file &&
922960 blob=$(git hash-object -w file) &&
923961 file=$(sha1_file $blob) &&
924962 test_when_finished "remove_object $blob" &&
0 commit comments