3 # Copyright (c) 2008 Nicolas Pitre
6 test_description
='resilience to pack corruptions with redundant objects'
9 # Note: the test objects are created with knowledge of their pack encoding
10 # to ensure good code path coverage, and to facilitate direct alteration
11 # later on. The assumed characteristics are:
13 # 1) blob_2 is a delta with blob_1 for base and blob_3 is a delta with blob2
14 # for base, such that blob_3 delta depth is 2;
16 # 2) the bulk of object data is uncompressible so the text part remains
19 # 3) object header is always 2 bytes.
22 test-genrandom
"foo" 2000 > file_1
&&
23 test-genrandom
"foo" 1800 > file_2
&&
24 test-genrandom
"foo" 1800 > file_3
&&
25 echo " base " >> file_1
&&
26 echo " delta1 " >> file_2
&&
27 echo " delta delta2 " >> file_3
&&
28 test-genrandom
"bar" 150 >> file_2
&&
29 test-genrandom
"baz" 100 >> file_3
35 blob_1
=`git hash-object -t blob -w file_1` &&
36 blob_2
=`git hash-object -t blob -w file_2` &&
37 blob_3
=`git hash-object -t blob -w file_3` &&
38 pack
=`printf "$blob_1\n$blob_2\n$blob_3\n" |
39 git pack-objects $@ .git/objects/pack/pack` &&
40 pack
=".git/objects/pack/pack-${pack}" &&
41 git verify-pack
-v ${pack}.pack
45 pack
=`printf "$blob_1\n$blob_2\n$blob_3\n" |
46 git pack-objects $@ .git/objects/pack/pack` &&
47 pack
=".git/objects/pack/pack-${pack}"
51 ofs
=`git show-index < ${pack}.idx | grep $1 | cut -f1 -d" "` &&
53 chmod +w
${pack}.pack
&&
54 dd of
=${pack}.pack count
=1 bs
=1 conv
=notrunc seek
=$ofs &&
55 test_must_fail git verify-pack
${pack}.pack
61 'initial setup validation' \
65 git cat-file blob $blob_1 > /dev/null &&
66 git cat-file blob $blob_2 > /dev/null &&
67 git cat-file blob $blob_3 > /dev/null'
70 'create corruption in header of first object' \
71 'do_corrupt_object $blob_1 0 < zero &&
72 test_must_fail git cat-file blob $blob_1 > /dev/null &&
73 test_must_fail git cat-file blob $blob_2 > /dev/null &&
74 test_must_fail git cat-file blob $blob_3 > /dev/null'
77 '... but having a loose copy allows for full recovery' \
78 'mv ${pack}.idx tmp &&
79 git hash-object -t blob -w file_1 &&
81 git cat-file blob $blob_1 > /dev/null &&
82 git cat-file blob $blob_2 > /dev/null &&
83 git cat-file blob $blob_3 > /dev/null'
86 '... and loose copy of first delta allows for partial recovery' \
88 test_must_fail git cat-file blob $blob_2 > /dev/null &&
90 git hash-object -t blob -w file_2 &&
92 test_must_fail git cat-file blob $blob_1 > /dev/null &&
93 git cat-file blob $blob_2 > /dev/null &&
94 git cat-file blob $blob_3 > /dev/null'
97 'create corruption in data of first object' \
100 chmod +w ${pack}.pack &&
101 "$PERL_PATH" -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
102 test_must_fail git cat-file blob $blob_1 > /dev/null &&
103 test_must_fail git cat-file blob $blob_2 > /dev/null &&
104 test_must_fail git cat-file blob $blob_3 > /dev/null'
106 test_expect_success \
107 '... but having a loose copy allows for full recovery' \
108 'mv ${pack}.idx tmp &&
109 git hash-object -t blob -w file_1 &&
110 mv tmp ${pack}.idx &&
111 git cat-file blob $blob_1 > /dev/null &&
112 git cat-file blob $blob_2 > /dev/null &&
113 git cat-file blob $blob_3 > /dev/null'
115 test_expect_success \
116 '... and loose copy of second object allows for partial recovery' \
118 test_must_fail git cat-file blob $blob_2 > /dev/null &&
119 mv ${pack}.idx tmp &&
120 git hash-object -t blob -w file_2 &&
121 mv tmp ${pack}.idx &&
122 test_must_fail git cat-file blob $blob_1 > /dev/null &&
123 git cat-file blob $blob_2 > /dev/null &&
124 git cat-file blob $blob_3 > /dev/null'
126 test_expect_success \
127 'create corruption in header of first delta' \
130 do_corrupt_object $blob_2 0 < zero &&
131 git cat-file blob $blob_1 > /dev/null &&
132 test_must_fail git cat-file blob $blob_2 > /dev/null &&
133 test_must_fail git cat-file blob $blob_3 > /dev/null'
135 test_expect_success \
136 '... but having a loose copy allows for full recovery' \
137 'mv ${pack}.idx tmp &&
138 git hash-object -t blob -w file_2 &&
139 mv tmp ${pack}.idx &&
140 git cat-file blob $blob_1 > /dev/null &&
141 git cat-file blob $blob_2 > /dev/null &&
142 git cat-file blob $blob_3 > /dev/null'
144 test_expect_success \
145 '... and then a repack "clears" the corruption' \
148 git verify-pack ${pack}.pack &&
149 git cat-file blob $blob_1 > /dev/null &&
150 git cat-file blob $blob_2 > /dev/null &&
151 git cat-file blob $blob_3 > /dev/null'
153 test_expect_success \
154 'create corruption in data of first delta' \
157 chmod +w ${pack}.pack &&
158 "$PERL_PATH" -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
159 git cat-file blob $blob_1 > /dev/null &&
160 test_must_fail git cat-file blob $blob_2 > /dev/null &&
161 test_must_fail git cat-file blob $blob_3 > /dev/null'
163 test_expect_success \
164 '... but having a loose copy allows for full recovery' \
165 'mv ${pack}.idx tmp &&
166 git hash-object -t blob -w file_2 &&
167 mv tmp ${pack}.idx &&
168 git cat-file blob $blob_1 > /dev/null &&
169 git cat-file blob $blob_2 > /dev/null &&
170 git cat-file blob $blob_3 > /dev/null'
172 test_expect_success \
173 '... and then a repack "clears" the corruption' \
176 git verify-pack ${pack}.pack &&
177 git cat-file blob $blob_1 > /dev/null &&
178 git cat-file blob $blob_2 > /dev/null &&
179 git cat-file blob $blob_3 > /dev/null'
181 test_expect_success \
182 'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \
185 do_corrupt_object $blob_2 2 < zero &&
186 git cat-file blob $blob_1 > /dev/null &&
187 test_must_fail git cat-file blob $blob_2 > /dev/null &&
188 test_must_fail git cat-file blob $blob_3 > /dev/null'
190 test_expect_success \
191 '... but having a loose copy allows for full recovery' \
192 'mv ${pack}.idx tmp &&
193 git hash-object -t blob -w file_2 &&
194 mv tmp ${pack}.idx &&
195 git cat-file blob $blob_1 > /dev/null &&
196 git cat-file blob $blob_2 > /dev/null &&
197 git cat-file blob $blob_3 > /dev/null'
199 test_expect_success \
200 '... and then a repack "clears" the corruption' \
203 git verify-pack ${pack}.pack &&
204 git cat-file blob $blob_1 > /dev/null &&
205 git cat-file blob $blob_2 > /dev/null &&
206 git cat-file blob $blob_3 > /dev/null'
208 test_expect_success \
209 'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' \
210 'create_new_pack --delta-base-offset &&
212 do_corrupt_object $blob_2 2 < zero &&
213 git cat-file blob $blob_1 > /dev/null &&
214 test_must_fail git cat-file blob $blob_2 > /dev/null &&
215 test_must_fail git cat-file blob $blob_3 > /dev/null'
217 test_expect_success \
218 '... but having a loose copy allows for full recovery' \
219 'mv ${pack}.idx tmp &&
220 git hash-object -t blob -w file_2 &&
221 mv tmp ${pack}.idx &&
222 git cat-file blob $blob_1 > /dev/null &&
223 git cat-file blob $blob_2 > /dev/null &&
224 git cat-file blob $blob_3 > /dev/null'
226 test_expect_success \
227 '... and then a repack "clears" the corruption' \
228 'do_repack --delta-base-offset &&
230 git verify-pack ${pack}.pack &&
231 git cat-file blob $blob_1 > /dev/null &&
232 git cat-file blob $blob_2 > /dev/null &&
233 git cat-file blob $blob_3 > /dev/null'
235 test_expect_success \
236 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \
237 'create_new_pack --delta-base-offset &&
239 printf "\001" | do_corrupt_object $blob_2 2 &&
240 git cat-file blob $blob_1 > /dev/null &&
241 test_must_fail git cat-file blob $blob_2 > /dev/null &&
242 test_must_fail git cat-file blob $blob_3 > /dev/null'
244 test_expect_success \
245 '... but having a loose copy allows for full recovery' \
246 'mv ${pack}.idx tmp &&
247 git hash-object -t blob -w file_2 &&
248 mv tmp ${pack}.idx &&
249 git cat-file blob $blob_1 > /dev/null &&
250 git cat-file blob $blob_2 > /dev/null &&
251 git cat-file blob $blob_3 > /dev/null'
253 test_expect_success \
254 '... and then a repack "clears" the corruption' \
255 'do_repack --delta-base-offset &&
257 git verify-pack ${pack}.pack &&
258 git cat-file blob $blob_1 > /dev/null &&
259 git cat-file blob $blob_2 > /dev/null &&
260 git cat-file blob $blob_3 > /dev/null'
262 test_expect_success \
263 '... and a redundant pack allows for full recovery too' \
264 'do_corrupt_object $blob_2 2 < zero &&
265 git cat-file blob $blob_1 > /dev/null &&
266 test_must_fail git cat-file blob $blob_2 > /dev/null &&
267 test_must_fail git cat-file blob $blob_3 > /dev/null &&
268 mv ${pack}.idx tmp &&
269 git hash-object -t blob -w file_1 &&
270 git hash-object -t blob -w file_2 &&
271 printf "$blob_1\n$blob_2\n" | git pack-objects .git/objects/pack/pack &&
273 mv tmp ${pack}.idx &&
274 git cat-file blob $blob_1 > /dev/null &&
275 git cat-file blob $blob_2 > /dev/null &&
276 git cat-file blob $blob_3 > /dev/null'
278 test_expect_success \
279 'corrupting header to have too small output buffer fails unpack' \
282 printf "\262\001" | do_corrupt_object $blob_1 0 &&
283 test_must_fail git cat-file blob $blob_1 > /dev/null &&
284 test_must_fail git cat-file blob $blob_2 > /dev/null &&
285 test_must_fail git cat-file blob $blob_3 > /dev/null'