interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4141-apply-too-large.sh

71 lines · 1862 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git apply with too-large patch'
4
5. ./test-lib.sh
6
7test_expect_success EXPENSIVE 'git apply rejects patches that are too large' '
8 {
9 cat <<-\EOF &&
10 diff --git a/file b/file
11 new file mode 100644
12 --- /dev/null
13 +++ b/file
14 @@ -0,0 +1 @@
15 EOF
16 test-tool genzeros $((1024 * 1024 * 1023))
17 } | test_must_fail git apply 2>err &&
18 test_grep "patch too large" err
19'
20
21test_expect_success EXPENSIVE 'git apply rejects binary patches that are too large' '
22 sz=$((1024 * 1024 * 2048)) &&
23 test-tool genzeros $sz | test-tool zlib deflate | test-tool base85 chunk-encode >payload &&
24 {
25 # Although the patch requires the correct blob ID, blob ID validation
26 # happens after the inflated content size check, so use $EMPTY_BLOB as
27 # a filler.
28 cat <<-EOF &&
29 diff --git a/file b/file
30 new file mode 100644
31 index $ZERO_OID..$EMPTY_BLOB
32 GIT binary patch
33 literal $sz
34 EOF
35 cat payload
36 } | test_must_fail git apply 2>err &&
37 test_grep "patch too large" err
38'
39
40test_expect_success EXPENSIVE 'git apply rejects large binary patches with incorrect size' '
41 sz=$((1024 * 1024 * 1023)) &&
42 test-tool genrandom foo $sz | test-tool zlib deflate | test-tool base85 chunk-encode >payload &&
43 {
44 cat <<-EOF &&
45 diff --git a/file b/file
46 new file mode 100644
47 index $ZERO_OID..$EMPTY_BLOB
48 GIT binary patch
49 literal 10
50 EOF
51 cat payload
52 } | test_must_fail git apply 2>err &&
53 test_grep "patch too large" err
54'
55
56test_expect_success 'git apply rejects binary patches with incorrect size' '
57 test-tool genrandom foo 100 | test-tool zlib deflate | test-tool base85 chunk-encode >payload &&
58 {
59 cat <<-EOF &&
60 diff --git a/file b/file
61 new file mode 100644
62 index $ZERO_OID..$EMPTY_BLOB
63 GIT binary patch
64 literal 10
65 EOF
66 cat payload
67 } | test_must_fail git apply 2>err &&
68 test_grep "corrupt binary patch" err
69'
70
71test_done