From 5edcd421d9c170ea30ac9ef82df8f574b6a16dae Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 12 Aug 2019 18:34:37 +0200 Subject: [PATCH] libjpeg-turbo: enable i386 architecture and improve fuzzer regarding msan (#2680) --- .../libjpeg-turbo/libjpeg_turbo_fuzzer.cc | 20 ++++++++++++++++++- projects/libjpeg-turbo/project.yaml | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) 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