2019-06-15 15:37:10 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
require 5.008;
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Digest::SHA;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
require TestDriver;
|
|
|
|
|
|
|
|
my $td = new TestDriver('fuzz');
|
|
|
|
|
2022-03-05 13:21:30 +00:00
|
|
|
my $qpdf_corpus = $ENV{'QPDF_FUZZ_CORPUS'} || die "must set QPDF_FUZZ_CORPUS";
|
2019-06-15 15:37:10 +00:00
|
|
|
|
2019-06-23 18:31:35 +00:00
|
|
|
my @fuzzers = (
|
|
|
|
['ascii85' => 1],
|
2024-07-11 12:27:50 +00:00
|
|
|
['dct' => 4],
|
2019-06-23 18:31:35 +00:00
|
|
|
['flate' => 1],
|
|
|
|
['hex' => 1],
|
2024-02-06 20:30:29 +00:00
|
|
|
['json' => 40],
|
2019-08-26 01:23:19 +00:00
|
|
|
['lzw' => 2],
|
2019-06-23 18:31:35 +00:00
|
|
|
['pngpredictor' => 1],
|
|
|
|
['runlength' => 6],
|
2024-01-21 16:27:37 +00:00
|
|
|
['tiffpredictor' => 2],
|
2024-07-28 17:10:02 +00:00
|
|
|
['qpdf' => 73], # increment when adding new files
|
2019-06-23 18:31:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my $n_tests = 0;
|
|
|
|
# One test for each directory for file count, two tests for each file
|
|
|
|
# in each directory
|
|
|
|
foreach my $d (@fuzzers)
|
2019-06-15 15:37:10 +00:00
|
|
|
{
|
2019-06-23 18:31:35 +00:00
|
|
|
$n_tests += 1 + (2 * $d->[1]);
|
2019-06-15 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 18:31:35 +00:00
|
|
|
foreach my $d (@fuzzers)
|
2019-06-15 15:37:10 +00:00
|
|
|
{
|
2019-06-23 18:31:35 +00:00
|
|
|
my $k = $d->[0];
|
|
|
|
my $dir = "../${k}_fuzzer_seed_corpus";
|
|
|
|
if (! -d $dir)
|
|
|
|
{
|
2022-03-05 13:21:30 +00:00
|
|
|
$dir = $qpdf_corpus;
|
2019-06-23 18:31:35 +00:00
|
|
|
}
|
|
|
|
my @files = glob("$dir/*");
|
|
|
|
$td->runtest("file count for $dir",
|
|
|
|
{$td->STRING => scalar(@files) . "\n"},
|
|
|
|
{$td->STRING => $d->[1] . "\n"},
|
2019-06-15 15:37:10 +00:00
|
|
|
$td->NORMALIZE_NEWLINES);
|
2019-06-23 18:31:35 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-06-15 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 18:31:35 +00:00
|
|
|
$td->report($n_tests);
|
2019-06-15 15:37:10 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|