diff --git a/projects/libjpeg-turbo/libjpeg_turbo_fuzzer.cc b/projects/libjpeg-turbo/libjpeg_turbo_fuzzer.cc index 838e5368a..1b9ffd62f 100644 --- a/projects/libjpeg-turbo/libjpeg_turbo_fuzzer.cc +++ b/projects/libjpeg-turbo/libjpeg_turbo_fuzzer.cc @@ -39,10 +39,28 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; } - std::unique_ptr buf(new unsigned char[width * height * 3]); + const int buffer_size = width * height * 3; + std::unique_ptr buf(new unsigned char[buffer_size]); tjDecompress2( jpegDecompressor, data, size, buf.get(), width, 0, height, TJPF_RGB, 0); + // For memory sanitizer, test each output byte + const unsigned char* raw_buf = buf.get(); + int count = 0; + for( int i = 0; i < buffer_size; i++ ) + { + if (raw_buf[i]) + { + count ++; + } + } + if (count == buffer_size) + { + // Do something with side effect, so that all the above tests don't + // get removed by the optimizer. + free(malloc(1)); + } + tjDestroy(jpegDecompressor); return 0; diff --git a/projects/libjpeg-turbo/project.yaml b/projects/libjpeg-turbo/project.yaml index f7e4ae56b..5ce3c80d1 100644 --- a/projects/libjpeg-turbo/project.yaml +++ b/projects/libjpeg-turbo/project.yaml @@ -3,3 +3,6 @@ sanitizers: - address - memory - undefined +architectures: + - x86_64 + - i386