As a test suite, run stand-alone fuzzer on seed corpus

Temporarily skip fuzz tests on Windows. There are Windows-specific
failures to address later.
This commit is contained in:
Jay Berkenbilt 2019-06-15 11:37:10 -04:00
parent e2c77bab89
commit bcfa407912
3 changed files with 58 additions and 0 deletions

View File

@ -1,5 +1,9 @@
2019-06-15 Jay Berkenbilt <ejb@ql.org>
* Do "ideal integration" with oss-fuzz. This includes adding a
better fuzzer with a seed corpus and adding automated tests of the
fuzzer with the test data.
* When parsing files, while reading an object, if there are too
many consecutive errors without enough intervening successes, give
up on the specific object. This reduces cases in which very badly

52
fuzz/qtest/fuzz.test Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Digest::SHA;
use File::Basename;
require TestDriver;
my $td = new TestDriver('fuzz');
if (($^O eq 'MSWin32') || ($^O eq 'msys'))
{
$td->emphasize("temporarily skipping fuzz tests in Windows");
$td->report(0);
exit(0);
}
my @files = glob("../qpdf_fuzzer_seed_corpus/*");
my $n_test_files = 27;
my $n_orig_files = 2559;
my $n_files = $n_test_files + $n_orig_files;
if (scalar(@files) != $n_files)
{
die "wrong number of files seen in fuzz.test";
}
foreach my $f (@files)
{
my $sum = basename($f);
$td->runtest("checksum $sum",
{$td->STRING => get_sha1_checksum($f)},
{$td->STRING => $sum});
$td->runtest("fuzz check $sum",
{$td->COMMAND => "qpdf_fuzzer $f"},
{$td->REGEXP => ".*$f successful\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
}
$td->report(2 * $n_files);
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;
}

View File

@ -642,6 +642,8 @@ my @bug_tests = (
["263", "empty xref stream", 2],
["335a", "ozz-fuzz-12152", 2],
["335b", "ozz-fuzz-14845", 2],
# When adding to this list, consider adding to SEED_CORPUS_FILES
# in fuzz/build.mk and updating the count in fuzz/qtest/fuzz.test.
);
$n_tests += scalar(@bug_tests);
foreach my $d (@bug_tests)