1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
#!/bin/bash
#
# Copyright 2008 Google Inc.
# Author: Lincoln Smith
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script tests the correctness of the vcdiff command-line executable.
# If you add a new test here, please add the same test to the Windows script
# vsprojects/vcdiff_test.bat.
#
# The caller should set the environment variable $srcdir to the root directory
# of the open-vcdiff package. ($srcdir is automatically provided by Automake
# when this script is run by "make check".)
# Find input files
VCDIFF=./vcdiff
# These options are only needed for the encoder;
# the decoder will recognize the interleaved and checksum formats
# without needing to specify any options.
VCD_OPTIONS="-interleaved -checksum"
DICTIONARY_FILE=$srcdir/testdata/configure.ac.v0.1
TARGET_FILE=$srcdir/testdata/configure.ac.v0.2
TEST_TMPDIR=${TMPDIR-/tmp}
DELTA_FILE=$TEST_TMPDIR/configure.ac.vcdiff
OUTPUT_TARGET_FILE=$TEST_TMPDIR/configure.ac.output
MALICIOUS_ENCODING=$srcdir/testdata/allocates_4gb.vcdiff
# vcdiff with no arguments shows usage information & error result
$VCDIFF \
&& { echo "vcdiff with no arguments should fail, but succeeded"; \
exit 1; }
echo "Test 1 ok";
# vcdiff with three arguments but without "encode" or "decode"
# shows usage information & error result
$VCDIFF $VCD_OPTIONS \
-dictionary $DICTIONARY_FILE -target $TARGET_FILE -delta $DELTA_FILE \
&& { echo "vcdiff without operation argument should fail, but succeeded"; \
exit 1; }
echo "Test 2 ok";
# vcdiff with all three arguments. Verify that output file matches target file
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
|| { echo "Encode with three arguments failed"; \
exit 1; }
$VCDIFF decode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
-target $OUTPUT_TARGET_FILE \
|| { echo "Decode with three arguments failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 3 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# vcdiff using stdin/stdout. Verify that output file matches target file
{ $VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
< $TARGET_FILE \
> $DELTA_FILE; } \
|| { echo "Encode using stdin/stdout failed"; \
exit 1; }
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
< $DELTA_FILE \
> $OUTPUT_TARGET_FILE; } \
|| { echo "Decode using stdin/stdout failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 4 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# vcdiff with mixed stdin/stdout.
{ $VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
> $DELTA_FILE; } \
|| { echo "Encode with mixed arguments failed"; \
exit 1; }
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
> $OUTPUT_TARGET_FILE; } \
|| { echo "Decode with mixed arguments failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 5 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
{ $VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
< $TARGET_FILE \
-delta $DELTA_FILE; } \
|| { echo "Encode with mixed arguments failed"; \
exit 1; }
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
< $DELTA_FILE \
-target $OUTPUT_TARGET_FILE; } \
|| { echo "Decode with mixed arguments failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 6 ok";
rm $OUTPUT_TARGET_FILE
# Don't remove $DELTA_FILE; use it for the next test
# If using the wrong dictionary, and dictionary is smaller than the original
# dictionary, vcdiff will spot the mistake and return an error. (It can't
# detect the case where the wrong dictionary is larger than the right one.)
$VCDIFF decode -dictionary $TARGET_FILE \
-delta $DELTA_FILE \
-target $OUTPUT_TARGET_FILE \
&& { echo "Decode using larger dictionary should fail, but succeeded"; \
exit 1; }
echo "Test 7 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# "vcdiff test" with all three arguments.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
|| { echo "vcdiff test with three arguments failed"; \
exit 1; }
echo "Test 8 ok";
rm $DELTA_FILE
# Dictionary file not found.
$VCDIFF $VCD_OPTIONS \
encode -dictionary $TEST_TMPDIR/nonexistent_file \
-target $TARGET_FILE \
-delta $DELTA_FILE \
&& { echo "vcdiff with missing dictionary file should fail, but succeeded"; \
exit 1; }
echo "Test 9 ok";
# Target file not found.
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TEST_TMPDIR/nonexistent_file \
-delta $DELTA_FILE \
&& { echo "vcdiff with missing target file should fail, but succeeded"; \
exit 1; }
echo "Test 10 ok";
# Delta file not found.
$VCDIFF decode -dictionary $DICTIONARY_FILE \
-delta $TEST_TMPDIR/nonexistent_file \
-target $OUTPUT_TARGET_FILE \
&& { echo "vcdiff with missing delta file should fail, but succeeded"; \
exit 1; }
echo "Test 11 ok";
# Try traversing an infinite loop of symbolic links.
ln -s $TEST_TMPDIR/infinite_loop1 $TEST_TMPDIR/infinite_loop2
ln -s $TEST_TMPDIR/infinite_loop2 $TEST_TMPDIR/infinite_loop1
$VCDIFF $VCD_OPTIONS \
encode -dictionary $TEST_TMPDIR/infinite_loop1 \
-target $TEST_TMPDIR/infinite_loop2 \
-delta $DELTA_FILE \
&& { echo "vcdiff with symbolic link loop should fail, but succeeded"; \
exit 1; }
echo "Test 12 ok";
rm $TEST_TMPDIR/infinite_loop1 $TEST_TMPDIR/infinite_loop2
# Test using -stats flag
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-stats \
|| { echo "Encode with -stats failed"; \
exit 1; }
$VCDIFF -stats \
decode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
-target $OUTPUT_TARGET_FILE \
|| { echo "Decode with -stats failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 13 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# Using /dev/null as dictionary should work, but (because dictionary is empty)
# it will not produce a small delta file.
$VCDIFF $VCD_OPTIONS \
test -dictionary /dev/null \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-stats \
|| { echo "vcdiff test with /dev/null as dictionary failed"; \
exit 1; }
echo "Test 14 ok";
rm $DELTA_FILE
# Using /dev/kmem as dictionary or target should produce an error
# (permission denied, or too large, or special file type)
$VCDIFF $VCD_OPTIONS \
encode -dictionary /dev/kmem \
-target $TARGET_FILE \
-delta $DELTA_FILE \
&& { echo "vcdiff with /dev/kmem as dictionary should fail, but succeeded"; \
exit 1; }
echo "Test 15 ok";
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target /dev/kmem \
-delta $DELTA_FILE \
&& { echo "vcdiff with /dev/kmem as target should fail, but succeeded"; \
exit 1; }
echo "Test 16 ok";
# Decode using something that isn't a delta file
$VCDIFF decode -dictionary $DICTIONARY_FILE \
-delta /etc/fstab \
-target $OUTPUT_TARGET_FILE \
&& { echo "vcdiff with invalid delta file should fail, but succeeded"; \
exit 1; }
echo "Test 17 ok";
$VCDIFF $VCD_OPTIONS \
encode -target $TARGET_FILE \
-delta $DELTA_FILE \
-dictionary \
&& { echo "-dictionary option with no file name should fail, but succeeded"; \
exit 1; }
echo "Test 18 ok";
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
-target \
&& { echo "-target option with no file name should fail, but succeeded"; \
exit 1; }
echo "Test 19 ok";
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta \
&& { echo "-delta option with no file name should fail, but succeeded"; \
exit 1; }
echo "Test 20 ok";
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-buffersize \
&& { echo "-buffersize option with no argument should fail, but succeeded"; \
exit 1; }
echo "Test 21 ok";
# Using -buffersize=1 should still work.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-buffersize 1 \
-stats \
|| { echo "vcdiff test with -buffersize=1 failed"; \
exit 1; }
echo "Test 22 ok";
rm $DELTA_FILE
# Using -buffersize=1 with stdin/stdout means that vcdiff
# will create a separate target window for each byte read.
{ $VCDIFF encode -dictionary $DICTIONARY_FILE \
-buffersize 1 \
-stats \
< $TARGET_FILE \
> $DELTA_FILE; } \
|| { echo "Encode using stdin/stdout with -buffersize=1 failed"; \
exit 1; }
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
-buffersize 1 \
-stats \
< $DELTA_FILE \
> $OUTPUT_TARGET_FILE; } \
|| { echo "Decode using stdin/stdout with -buffersize=1 failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original with -buffersize=1"; \
exit 1; }
echo "Test 23 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# Using -buffersize=0 should fail.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-buffersize 0 \
&& { echo "vcdiff test with -buffersize=0 should fail, but succeeded"; \
exit 1; }
echo "Test 24 ok";
rm $DELTA_FILE
# Using -buffersize=128M (larger than default maximum) should still work.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-buffersize 134217728 \
-stats \
|| { echo "vcdiff test with -buffersize=128M failed"; \
exit 1; }
echo "Test 25 ok";
rm $DELTA_FILE
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-froobish \
&& { echo "vdiff test with unrecognized option should fail, but succeeded"; \
exit 1; }
echo "Test 26 ok";
$VCDIFF $VCD_OPTIONS \
encode -target $TARGET_FILE \
-delta $DELTA_FILE \
&& { echo "encode with no dictionary option should fail, but succeeded"; \
exit 1; }
echo "Test 27 ok";
$VCDIFF decode -target $TARGET_FILE \
-delta $DELTA_FILE \
&& { echo "decode with no dictionary option should fail, but succeeded"; \
exit 1; }
echo "Test 28 ok";
# Remove -interleaved and -checksum options
{ $VCDIFF encode -dictionary $DICTIONARY_FILE \
< $TARGET_FILE \
> $DELTA_FILE; } \
|| { echo "Encode without -interleaved and -checksum options failed"; \
exit 1; }
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
< $DELTA_FILE \
> $OUTPUT_TARGET_FILE; } \
|| { echo "Decode non-interleaved output failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original with -interleaved"; \
exit 1; }
echo "Test 29 ok";
# -target_matches option
{ $VCDIFF encode -dictionary $DICTIONARY_FILE \
-target_matches \
-stats \
< $TARGET_FILE \
> $DELTA_FILE; } \
|| { echo "Encode with -target_matches option failed"; \
exit 1; }
# The decode operation ignores the -target_matches option.
{ $VCDIFF decode -dictionary $DICTIONARY_FILE \
< $DELTA_FILE \
> $OUTPUT_TARGET_FILE; } \
|| { echo "Decode output failed with -target_matches"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original with -target_matches"; \
exit 1; }
echo "Test 30 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
$VCDIFF $VCD_OPTIONS \
dencode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
&& { echo "vdiff with unrecognized action should fail, but succeeded"; \
exit 1; }
echo "Test 31 ok";
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
&& { echo "vdiff test without delta option should fail, but succeeded"; \
exit 1; }
echo "Test 32 ok";
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
&& { echo "vdiff test without target option should fail, but succeeded"; \
exit 1; }
echo "Test 33 ok";
# open-vcdiff bug 8 (http://code.google.com/p/open-vcdiff/issues/detail?id=8)
# A malicious encoding that tries to produce a 4GB target file made up of 64
# windows, each window having a size of 64MB.
# Limit memory usage to 256MB per process, so the test doesn't take forever
# to run out of memory.
OLD_ULIMIT=$(ulimit -v)
echo "Old ulimit: $OLD_ULIMIT"
ulimit -S -v 262144
echo "New ulimit: $(ulimit -v)"
$VCDIFF $VCD_OPTIONS \
decode -dictionary $DICTIONARY_FILE \
-delta $MALICIOUS_ENCODING \
-target /dev/null \
-max_target_file_size=65536 \
&& { echo "Decoding malicious file should fail, but succeeded"; \
exit 1; }
echo "Test 34 ok";
$VCDIFF $VCD_OPTIONS \
decode -dictionary $DICTIONARY_FILE \
-delta $MALICIOUS_ENCODING \
-target /dev/null \
-max_target_window_size=65536 \
&& { echo "Decoding malicious file should fail, but succeeded"; \
exit 1; }
echo "Test 35 ok";
ulimit -S -v $OLD_ULIMIT
# Decoding a small target with the -max_target_file_size option should succeed.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-max_target_file_size=65536 \
|| { echo "vcdiff test with -max_target_file_size failed"; \
exit 1; }
echo "Test 36 ok";
# Decoding a small target with -max_target_window_size option should succeed.
$VCDIFF $VCD_OPTIONS \
test -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-max_target_window_size=65536 \
|| { echo "vcdiff test with -max_target_window_size failed"; \
exit 1; }
echo "Test 37 ok";
rm $DELTA_FILE
# Test using -allow_vcd_target=false
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-allow_vcd_target=false \
|| { echo "Encode with -allow_vcd_target=false failed"; \
exit 1; }
$VCDIFF $VCD_OPTIONS \
decode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
-target $OUTPUT_TARGET_FILE \
-allow_vcd_target=false \
|| { echo "Decode with -allow_vcd_target=false failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 38 ok";
rm $DELTA_FILE
rm $OUTPUT_TARGET_FILE
# Test using -allow_vcd_target=true
$VCDIFF $VCD_OPTIONS \
encode -dictionary $DICTIONARY_FILE \
-target $TARGET_FILE \
-delta $DELTA_FILE \
-allow_vcd_target=true \
|| { echo "Encode with -allow_vcd_target=true failed"; \
exit 1; }
$VCDIFF $VCD_OPTIONS \
decode -dictionary $DICTIONARY_FILE \
-delta $DELTA_FILE \
-target $OUTPUT_TARGET_FILE \
-allow_vcd_target=true \
|| { echo "Decode with -allow_vcd_target=true failed"; \
exit 1; }
cmp $TARGET_FILE $OUTPUT_TARGET_FILE \
|| { echo "Decoded target does not match original"; \
exit 1; }
echo "Test 39 ok";
echo "PASS"
|