Commit 232f5fc9f3bed8e1b02bca5d10b2eca444e30f95

Authored by Jay Berkenbilt
1 parent c1684eae

Handle jpeg library fuzz false positives

The jpeg library has some assembly code that is missed by the compiler
instrumentation used by memory sanitization. There is a runtime
environment variable that is used to work around this issue.
fuzz/dct_fuzzer.cc
... ... @@ -2,6 +2,7 @@
2 2 #include <qpdf/Pl_DCT.hh>
3 3 #include <iostream>
4 4 #include <stdexcept>
  5 +#include <cstdlib>
5 6  
6 7 class FuzzHelper
7 8 {
... ... @@ -46,6 +47,11 @@ FuzzHelper::run()
46 47  
47 48 extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
48 49 {
  50 +#ifndef _WIN32
  51 + // Used by jpeg library to work around false positives in memory
  52 + // sanitizer.
  53 + setenv("JSIMD_FORCENONE", "1", 1);
  54 +#endif
49 55 FuzzHelper f(data, size);
50 56 f.run();
51 57 return 0;
... ...
fuzz/qpdf_fuzzer.cc
... ... @@ -9,6 +9,7 @@
9 9 #include <qpdf/QPDFPageLabelDocumentHelper.hh>
10 10 #include <qpdf/QPDFOutlineDocumentHelper.hh>
11 11 #include <qpdf/QPDFAcroFormDocumentHelper.hh>
  12 +#include <cstdlib>
12 13  
13 14 class DiscardContents: public QPDFObjectHandle::ParserCallbacks
14 15 {
... ... @@ -223,6 +224,11 @@ FuzzHelper::run()
223 224  
224 225 extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size)
225 226 {
  227 +#ifndef _WIN32
  228 + // Used by jpeg library to work around false positives in memory
  229 + // sanitizer.
  230 + setenv("JSIMD_FORCENONE", "1", 1);
  231 +#endif
226 232 FuzzHelper f(data, size);
227 233 f.run();
228 234 return 0;
... ...
libqpdf/Pl_DCT.cc
... ... @@ -8,6 +8,7 @@
8 8 #include <stdexcept>
9 9 #include <stdlib.h>
10 10 #include <string>
  11 +#include <cstring>
11 12  
12 13 #if BITS_IN_JSAMPLE != 8
13 14 # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8"
... ...