mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-16 09:37:08 +00:00
e4ef3d1540
Since the introduction of fuzz testing, there has never been a problem found because of a failure of a file in the fuzzer seed corpus. As the fuzzer has found problems, they have been added to the test suite, and that should be adequate to exercise the fuzzers in the tesing environment as well as providing adequate regression testing. Removing these original files shaves many minutes off the builds in CI.
76 lines
1.8 KiB
Perl
76 lines
1.8 KiB
Perl
#!/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_n_test_files = 31;
|
|
my @extra = glob("../qpdf_extra/*.fuzz");
|
|
my $qpdf_n_extra_files = scalar(@extra);
|
|
my $qpdf_n_files = ($qpdf_n_test_files + $qpdf_n_extra_files);
|
|
|
|
my @fuzzers = (
|
|
['ascii85' => 1],
|
|
['dct' => 1],
|
|
['flate' => 1],
|
|
['hex' => 1],
|
|
['lzw' => 2],
|
|
['pngpredictor' => 1],
|
|
['runlength' => 6],
|
|
['tiffpredictor' => 1],
|
|
['qpdf' => $qpdf_n_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 = "../build/${k}_fuzzer_seed_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;
|
|
}
|