| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "malformed pointers" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="malformed-pointers" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | git add .gitattributes |
| 15 | git commit -m "initial commit" |
| 16 | |
| 17 | # Test with file sizes smaller than, equal to, and larger than the |
| 18 | # size of the read buffer used when decoding pointers. |
| 19 | # See https://github.com/git-lfs/git-lfs/issues/1729 |
| 20 | # and https://github.com/git-lfs/git-lfs/pull/1796. |
| 21 | max_pointer_size="$(lfstest-getlimit --max-pointer-size)" |
| 22 | lfstest-genrandom --base64 $((max_pointer_size - 1)) >malformed_small.dat |
| 23 | lfstest-genrandom --base64 "$max_pointer_size" >malformed_exact.dat |
| 24 | lfstest-genrandom --base64 $((max_pointer_size + 1)) >malformed_large.dat |
| 25 | |
| 26 | # Test with a file size significantly larger than the default pipe capacity |
| 27 | # of Linux/macOS. See https://github.com/git-lfs/git-lfs/pull/1922 |
| 28 | # and https://github.com/git-lfs/git-lfs/pull/1932. |
| 29 | max_pipe_capacity="65536" |
| 30 | lfstest-genrandom --base64 $((max_pipe_capacity * 16)) >malformed_xxl.dat |
| 31 | |
| 32 | git \ |
| 33 | -c "filter.lfs.process=" \ |
| 34 | -c "filter.lfs.clean=cat" \ |
| 35 | -c "filter.lfs.required=false" \ |
| 36 | add *.dat |
| 37 | git commit -m "add malformed pointer" |
| 38 | |
| 39 | git push origin main |
| 40 | |
| 41 | pushd .. >/dev/null |
| 42 | clone_repo "$reponame" "$reponame-assert" |
| 43 | |
| 44 | grep "malformed_small.dat" clone.log |
| 45 | grep "malformed_exact.dat" clone.log |
| 46 | grep "malformed_large.dat" clone.log |
| 47 | grep "malformed_xxl.dat" clone.log |
| 48 | |
| 49 | expected_small="$(cat ../$reponame/malformed_small.dat)" |
| 50 | expected_exact="$(cat ../$reponame/malformed_exact.dat)" |
| 51 | expected_large="$(cat ../$reponame/malformed_large.dat)" |
| 52 | expected_xxl="$(cat ../$reponame/malformed_xxl.dat)" |
| 53 | |
| 54 | actual_small="$(cat malformed_small.dat)" |
| 55 | actual_exact="$(cat malformed_exact.dat)" |
| 56 | actual_large="$(cat malformed_large.dat)" |
| 57 | actual_xxl="$(cat malformed_xxl.dat)" |
| 58 | |
| 59 | [ "$expected_small" = "$actual_small" ] |
| 60 | [ "$expected_exact" = "$actual_exact" ] |
| 61 | [ "$expected_large" = "$actual_large" ] |
| 62 | [ "$expected_xxl" = "$actual_xxl" ] |
| 63 | popd >/dev/null |
| 64 | ) |
| 65 | end_test |
| 66 | |
| 67 | begin_test "empty pointers" |
| 68 | ( |
| 69 | set -e |
| 70 | |
| 71 | reponame="empty-pointers" |
| 72 | setup_remote_repo "$reponame" |
| 73 | clone_repo "$reponame" "$reponame" |
| 74 | |
| 75 | git lfs track "*.dat" |
| 76 | git add .gitattributes |
| 77 | git commit -m "initial commit" |
| 78 | |
| 79 | touch empty.dat |
| 80 | |
| 81 | git \ |
| 82 | -c "filter.lfs.process=" \ |
| 83 | -c "filter.lfs.clean=cat" \ |
| 84 | -c "filter.lfs.required=false" \ |
| 85 | add empty.dat |
| 86 | git commit -m "add empty pointer" |
| 87 | |
| 88 | [ "0" -eq "$(git cat-file -p :empty.dat | wc -c)" ] |
| 89 | [ "0" -eq "$(wc -c < empty.dat)" ] |
| 90 | |
| 91 | git push origin main |
| 92 | |
| 93 | pushd .. >/dev/null |
| 94 | clone_repo "$reponame" "$reponame-assert" |
| 95 | |
| 96 | [ "0" -eq "$(grep -c "empty.dat" clone.log)" ] |
| 97 | |
| 98 | [ "0" -eq "$(git cat-file -p :empty.dat | wc -c)" ] |
| 99 | [ "0" -eq "$(wc -c < empty.dat)" ] |
| 100 | popd >/dev/null |
| 101 | ) |
| 102 | end_test |