Commit e2c77bab89f9ac7d55b52697589feaf9afcf6c07

Authored by Jay Berkenbilt
1 parent 9d310374

Populate seed corpus

.gitignore
... ... @@ -25,3 +25,4 @@ manual/html.xsl
25 25 manual/print.xsl
26 26 qpdf/build/
27 27 zlib-flate/build/
  28 +fuzz/qpdf_fuzzer_seed_corpus/
... ...
fuzz/build.mk
... ... @@ -9,7 +9,7 @@ DEFAULT_FUZZ_RUNNER := standalone_fuzz_target_runner
9 9 OBJ_DEFAULT_FUZZ := fuzz/$(OUTPUT_DIR)/$(DEFAULT_FUZZ_RUNNER).$(OBJ)
10 10  
11 11 BINS_fuzz = $(foreach B,$(FUZZERS),fuzz/$(OUTPUT_DIR)/$(call binname,$(B)))
12   -TARGETS_fuzz = $(OBJ_DEFAULT_FUZZ) $(BINS_fuzz)
  12 +TARGETS_fuzz = $(OBJ_DEFAULT_FUZZ) $(BINS_fuzz) fuzz_corpus
13 13  
14 14 INCLUDES_fuzz = include
15 15  
... ... @@ -21,8 +21,58 @@ LIB_FUZZING_ENGINE ?= $(OBJ_DEFAULT_FUZZ)
21 21 # by oss-fuzz, it will be there.
22 22 $(BINS_fuzz): $(TARGETS_libqpdf) $(OBJ_DEFAULT_FUZZ)
23 23  
  24 +# Files from the test suite that are good for seeding the fuzzer.
  25 +# Update $n_test_files in qtest/fuzz.test if you change this list.
  26 +SEED_CORPUS_FILES = \
  27 + field-types.pdf \
  28 + image-streams.pdf \
  29 + need-appearances.pdf \
  30 + outlines-with-actions.pdf \
  31 + outlines-with-old-root-dests.pdf \
  32 + page-labels-and-outlines.pdf \
  33 + page-labels-num-tree.pdf \
  34 + issue-99b.pdf \
  35 + issue-99.pdf \
  36 + issue-100.pdf \
  37 + issue-101.pdf \
  38 + issue-106.pdf \
  39 + issue-117.pdf \
  40 + issue-119.pdf \
  41 + issue-120.pdf \
  42 + issue-141a.pdf \
  43 + issue-141b.pdf \
  44 + issue-143.pdf \
  45 + issue-146.pdf \
  46 + issue-147.pdf \
  47 + issue-148.pdf \
  48 + issue-149.pdf \
  49 + issue-150.pdf \
  50 + issue-202.pdf \
  51 + issue-263.pdf \
  52 + issue-335a.pdf \
  53 + issue-335b.pdf
  54 +
24 55 # -----
25 56  
  57 +CORPUS_FROM_TEST := $(foreach F,$(SEED_CORPUS_FILES),qpdf/qtest/qpdf/$F)
  58 +CORPUS_DIR := fuzz/qpdf_fuzzer_seed_corpus
  59 +
  60 +.PHONY: fuzz_corpus
  61 +fuzz_corpus:: fuzz/$(OUTPUT_DIR)/fuzz_corpus.stamp
  62 +$(foreach F,$(CORPUS_FROM_TEST),$(eval \
  63 + SHA1_$(notdir $(F)) := $(shell perl fuzz/get_sha1 < $F)))
  64 +$(foreach F,$(CORPUS_FROM_TEST),$(eval \
  65 + fuzz_corpus:: $(CORPUS_DIR)/$(SHA1_$(notdir $(F)))))
  66 +$(foreach F,$(CORPUS_FROM_TEST),$(eval \
  67 + $(CORPUS_DIR)/$(SHA1_$(notdir $(F))): $(F) ; \
  68 + mkdir -p $(CORPUS_DIR); \
  69 + cp $(F) $(CORPUS_DIR)/$(SHA1_$(notdir $(F)))))
  70 +
  71 +fuzz/$(OUTPUT_DIR)/fuzz_corpus.stamp: fuzz/original-corpus.tar.gz $(CORPUS_FROM_TEST)
  72 + mkdir -p $(CORPUS_DIR)
  73 + (cd $(CORPUS_DIR); tar xzf ../original-corpus.tar.gz)
  74 + touch $@
  75 +
26 76 $(foreach B,$(FUZZERS),$(eval \
27 77 OBJS_$(B) = $(call src_to_obj,fuzz/$(B).cc)))
28 78  
... ...
fuzz/get_sha1 0 → 100644
  1 +#!/usr/bin/env perl
  2 +require 5.008;
  3 +use warnings;
  4 +use strict;
  5 +use Digest::SHA;
  6 +
  7 +binmode STDIN;
  8 +my $digest = Digest::SHA->new('sha1')->addfile(*STDIN)->hexdigest;
  9 +print "$digest\n";
... ...