| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='handling of deep trees in various commands' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # We'll test against two depths here: a small one that will let us check the |
| 8 | # behavior of the config setting easily, and a large one that should be |
| 9 | # forbidden by default. Testing the default depth will let us know whether our |
| 10 | # default is enough to prevent segfaults on systems that run the tests. |
| 11 | small_depth=50 |
| 12 | big_depth=4100 |
| 13 | |
| 14 | small_ok="-c core.maxtreedepth=$small_depth" |
| 15 | small_no="-c core.maxtreedepth=$((small_depth-1))" |
| 16 | |
| 17 | # usage: mkdeep <name> <depth> |
| 18 | # Create a tag <name> containing a file whose path has depth <depth>. |
| 19 | # |
| 20 | # We'll use fast-import here for two reasons: |
| 21 | # |
| 22 | # 1. It's faster than creating $big_depth tree objects. |
| 23 | # |
| 24 | # 2. As we tighten tree limits, it's more likely to allow large sizes |
| 25 | # than trying to stuff a deep path into the index. |
| 26 | mkdeep () { |
| 27 | { |
| 28 | echo "commit refs/tags/$1" && |
| 29 | echo "committer foo <foo@example.com> 1234 -0000" && |
| 30 | echo "data <<EOF" && |
| 31 | echo "the commit message" && |
| 32 | echo "EOF" && |
| 33 | |
| 34 | printf 'M 100644 inline ' && |
| 35 | i=0 && |
| 36 | while test $i -lt $2 |
| 37 | do |
| 38 | printf 'a/' |
| 39 | i=$((i+1)) |
| 40 | done && |
| 41 | echo "file" && |
| 42 | |
| 43 | echo "data <<EOF" && |
| 44 | echo "the file contents" && |
| 45 | echo "EOF" && |
| 46 | echo |
| 47 | } | git fast-import |
| 48 | } |
| 49 | |
| 50 | test_expect_success 'create small tree' ' |
| 51 | mkdeep small $small_depth |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'create big tree' ' |
| 55 | mkdeep big $big_depth |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'limit recursion of git-archive' ' |
| 59 | git $small_ok archive small >/dev/null && |
| 60 | test_must_fail git $small_no archive small >/dev/null |
| 61 | ' |
| 62 | |
| 63 | test_expect_success 'default limit for git-archive fails gracefully' ' |
| 64 | test_must_fail git archive big >/dev/null |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'limit recursion of ls-tree -r' ' |
| 68 | git $small_ok ls-tree -r small && |
| 69 | test_must_fail git $small_no ls-tree -r small |
| 70 | ' |
| 71 | |
| 72 | test_expect_success 'default limit for ls-tree fails gracefully' ' |
| 73 | test_must_fail git ls-tree -r big >/dev/null |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'limit recursion of rev-list --objects' ' |
| 77 | git $small_ok rev-list --objects small >/dev/null && |
| 78 | test_must_fail git $small_no rev-list --objects small >/dev/null |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'default limit for rev-list fails gracefully' ' |
| 82 | test_must_fail git rev-list --objects big >/dev/null |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'limit recursion of diff-tree -r' ' |
| 86 | git $small_ok diff-tree -r $EMPTY_TREE small && |
| 87 | test_must_fail git $small_no diff-tree -r $EMPTY_TREE small |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'default limit for diff-tree fails gracefully' ' |
| 91 | test_must_fail git diff-tree -r $EMPTY_TREE big |
| 92 | ' |
| 93 | |
| 94 | test_done |