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
|
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Digest::SHA;
use File::Basename;
require TestDriver;
my $td = new TestDriver('fuzz');
my $qpdf_corpus = $ENV{'QPDF_FUZZ_CORPUS'} || die "must set QPDF_FUZZ_CORPUS";
my @fuzzers = (
['ascii85' => 1],
['dct' => 1],
['flate' => 1],
['hex' => 1],
['json' => 38],
['lzw' => 2],
['pngpredictor' => 1],
['runlength' => 6],
['tiffpredictor' => 2],
['qpdf' => 56], # increment when adding new files
);
my $n_tests = 0;
# One test for each directory for file count, two tests for each file
# in each directory
foreach my $d (@fuzzers)
{
$n_tests += 1 + (2 * $d->[1]);
}
foreach my $d (@fuzzers)
{
my $k = $d->[0];
my $dir = "../${k}_fuzzer_seed_corpus";
if (! -d $dir)
{
$dir = $qpdf_corpus;
}
my @files = glob("$dir/*");
$td->runtest("file count for $dir",
{$td->STRING => scalar(@files) . "\n"},
{$td->STRING => $d->[1] . "\n"},
$td->NORMALIZE_NEWLINES);
foreach my $f (@files)
{
my $sum = basename($f);
$td->runtest("$k checksum $sum",
{$td->STRING => get_sha1_checksum($f)},
{$td->STRING => $sum});
$td->runtest("$k fuzz check $sum",
{$td->COMMAND => "${k}_fuzzer $f"},
{$td->REGEXP => ".*$f successful\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
}
}
$td->report($n_tests);
sub get_sha1_checksum
{
my $file = shift;
open(F, "<$file") or fatal("can't open $file: $!");
binmode F;
my $digest = Digest::SHA->new('sha1')->addfile(*F)->hexdigest;
close(F);
$digest;
}
|