Commit 232f5fc9f3bed8e1b02bca5d10b2eca444e30f95
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.
Showing
3 changed files
with
13 additions
and
0 deletions
fuzz/dct_fuzzer.cc
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | #include <qpdf/Pl_DCT.hh> | 2 | #include <qpdf/Pl_DCT.hh> |
| 3 | #include <iostream> | 3 | #include <iostream> |
| 4 | #include <stdexcept> | 4 | #include <stdexcept> |
| 5 | +#include <cstdlib> | ||
| 5 | 6 | ||
| 6 | class FuzzHelper | 7 | class FuzzHelper |
| 7 | { | 8 | { |
| @@ -46,6 +47,11 @@ FuzzHelper::run() | @@ -46,6 +47,11 @@ FuzzHelper::run() | ||
| 46 | 47 | ||
| 47 | extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) | 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 | FuzzHelper f(data, size); | 55 | FuzzHelper f(data, size); |
| 50 | f.run(); | 56 | f.run(); |
| 51 | return 0; | 57 | return 0; |
fuzz/qpdf_fuzzer.cc
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | #include <qpdf/QPDFPageLabelDocumentHelper.hh> | 9 | #include <qpdf/QPDFPageLabelDocumentHelper.hh> |
| 10 | #include <qpdf/QPDFOutlineDocumentHelper.hh> | 10 | #include <qpdf/QPDFOutlineDocumentHelper.hh> |
| 11 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> | 11 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> |
| 12 | +#include <cstdlib> | ||
| 12 | 13 | ||
| 13 | class DiscardContents: public QPDFObjectHandle::ParserCallbacks | 14 | class DiscardContents: public QPDFObjectHandle::ParserCallbacks |
| 14 | { | 15 | { |
| @@ -223,6 +224,11 @@ FuzzHelper::run() | @@ -223,6 +224,11 @@ FuzzHelper::run() | ||
| 223 | 224 | ||
| 224 | extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) | 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 | FuzzHelper f(data, size); | 232 | FuzzHelper f(data, size); |
| 227 | f.run(); | 233 | f.run(); |
| 228 | return 0; | 234 | return 0; |
libqpdf/Pl_DCT.cc
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | #include <stdexcept> | 8 | #include <stdexcept> |
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 10 | #include <string> | 10 | #include <string> |
| 11 | +#include <cstring> | ||
| 11 | 12 | ||
| 12 | #if BITS_IN_JSAMPLE != 8 | 13 | #if BITS_IN_JSAMPLE != 8 |
| 13 | # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8" | 14 | # error "qpdf does not support libjpeg built with BITS_IN_JSAMPLE != 8" |