diff options
author | Amin Hassani <ahassani@google.com> | 2019-10-09 19:13:20 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-10-09 19:13:20 -0700 |
commit | cc4a0d00061ed9ac7cd886529b73e23436557179 (patch) | |
tree | 8d7545bc9bae9fc17f8e752b353624c72868d1a6 | |
parent | bc7745523aef2d7f620ca16aa6ab11a8e38dc60e (diff) | |
parent | 5bf39c93ae9e7f5ed7a21f16e384d9304398531d (diff) | |
download | puffin-android10-mainline-resolv-release.tar.gz |
Break puffin_fuzzer into three fuzzers am: ba2b2a9c0c am: 27423c2cdbandroid-mainline-10.0.0_r8android-mainline-10.0.0_r6android10-mainline-resolv-releaseandroid10-mainline-networking-release
am: 5bf39c93ae
Change-Id: I987203098187d13bec6bf746de62532637894553
-rw-r--r-- | BUILD.gn | 36 | ||||
-rw-r--r-- | src/fuzzer_huff.cc | 43 | ||||
-rw-r--r-- | src/fuzzer_puff.cc | 47 | ||||
-rw-r--r-- | src/fuzzer_puffpatch.cc (renamed from src/fuzzer.cc) | 38 |
4 files changed, 127 insertions, 37 deletions
@@ -16,7 +16,11 @@ group("all") { deps += [ ":puffin_test" ] } if (use.fuzzer) { - deps += [ ":puffin_fuzzer" ] + deps += [ + ":puffin_huff_fuzzer", + ":puffin_puff_fuzzer", + ":puffin_puffpatch_fuzzer", + ] } } @@ -138,7 +142,33 @@ if (use.test) { } if (use.fuzzer) { - executable("puffin_fuzzer") { + executable("puffin_huff_fuzzer") { + configs += [ + "//common-mk/common_fuzzer", + ":libbrillo", + ":target_defaults", + ] + deps = [ + ":libpuffpatch", + ] + sources = [ + "src/fuzzer_huff.cc", + ] + } + executable("puffin_puff_fuzzer") { + configs += [ + "//common-mk/common_fuzzer", + ":libbrillo", + ":target_defaults", + ] + deps = [ + ":libpuffpatch", + ] + sources = [ + "src/fuzzer_puff.cc", + ] + } + executable("puffin_puffpatch_fuzzer") { configs += [ "//common-mk/common_fuzzer", ":libbrillo", @@ -148,7 +178,7 @@ if (use.fuzzer) { ":libpuffdiff", ] sources = [ - "src/fuzzer.cc", + "src/fuzzer_puffpatch.cc", ] } } diff --git a/src/fuzzer_huff.cc b/src/fuzzer_huff.cc new file mode 100644 index 0000000..4002aa0 --- /dev/null +++ b/src/fuzzer_huff.cc @@ -0,0 +1,43 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/logging.h" +#include "brillo/test_helpers.h" + +#include "puffin/src/bit_writer.h" +#include "puffin/src/include/puffin/common.h" +#include "puffin/src/include/puffin/huffer.h" +#include "puffin/src/puff_reader.h" + +using puffin::Buffer; +using puffin::BufferBitWriter; +using puffin::BufferPuffReader; +using puffin::ByteExtent; +using puffin::Huffer; + +namespace { +void FuzzHuff(const uint8_t* data, size_t size) { + BufferPuffReader puff_reader(data, size); + Buffer deflate_buffer(size); + BufferBitWriter bit_writer(deflate_buffer.data(), deflate_buffer.size()); + Huffer huffer; + huffer.HuffDeflate(&puff_reader, &bit_writer); +} + +class Environment { + public: + Environment() { + // To turn off the logging. + logging::SetMinLogLevel(logging::LOG_FATAL); + } +}; + +} // namespace + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + static Environment env; + + FuzzHuff(data, size); + return 0; +} diff --git a/src/fuzzer_puff.cc b/src/fuzzer_puff.cc new file mode 100644 index 0000000..c4d26f6 --- /dev/null +++ b/src/fuzzer_puff.cc @@ -0,0 +1,47 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <vector> + +#include "base/logging.h" +#include "brillo/test_helpers.h" + +#include "puffin/src/bit_reader.h" +#include "puffin/src/include/puffin/common.h" +#include "puffin/src/include/puffin/puffer.h" +#include "puffin/src/puff_writer.h" + +using puffin::BitExtent; +using puffin::Buffer; +using puffin::BufferBitReader; +using puffin::BufferPuffWriter; +using puffin::Puffer; +using std::vector; + +namespace { +void FuzzPuff(const uint8_t* data, size_t size) { + BufferBitReader bit_reader(data, size); + Buffer puff_buffer(size * 2); + BufferPuffWriter puff_writer(puff_buffer.data(), puff_buffer.size()); + vector<BitExtent> bit_extents; + Puffer puffer; + puffer.PuffDeflate(&bit_reader, &puff_writer, &bit_extents); +} + +class Environment { + public: + Environment() { + // To turn off the logging. + logging::SetMinLogLevel(logging::LOG_FATAL); + } +}; + +} // namespace + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + static Environment env; + + FuzzPuff(data, size); + return 0; +} diff --git a/src/fuzzer.cc b/src/fuzzer_puffpatch.cc index b870ac4..28ee5bc 100644 --- a/src/fuzzer.cc +++ b/src/fuzzer_puffpatch.cc @@ -7,27 +7,14 @@ #include "base/logging.h" #include "brillo/test_helpers.h" -#include "puffin/src/bit_reader.h" -#include "puffin/src/bit_writer.h" #include "puffin/src/include/puffin/common.h" -#include "puffin/src/include/puffin/huffer.h" -#include "puffin/src/include/puffin/puffer.h" #include "puffin/src/include/puffin/puffpatch.h" #include "puffin/src/memory_stream.h" -#include "puffin/src/puff_reader.h" -#include "puffin/src/puff_writer.h" using puffin::BitExtent; using puffin::Buffer; -using puffin::BufferBitReader; -using puffin::BufferBitWriter; -using puffin::BufferPuffReader; -using puffin::BufferPuffWriter; using puffin::ByteExtent; -using puffin::Huffer; using puffin::MemoryStream; -using puffin::Puffer; -using puffin::UniqueStreamPtr; using std::vector; namespace puffin { @@ -45,23 +32,6 @@ bool DecodePatch(const uint8_t* patch, } // namespace puffin namespace { -void FuzzPuff(const uint8_t* data, size_t size) { - BufferBitReader bit_reader(data, size); - Buffer puff_buffer(size * 2); - BufferPuffWriter puff_writer(puff_buffer.data(), puff_buffer.size()); - vector<BitExtent> bit_extents; - Puffer puffer; - puffer.PuffDeflate(&bit_reader, &puff_writer, &bit_extents); -} - -void FuzzHuff(const uint8_t* data, size_t size) { - BufferPuffReader puff_reader(data, size); - Buffer deflate_buffer(size); - BufferBitWriter bit_writer(deflate_buffer.data(), deflate_buffer.size()); - Huffer huffer; - huffer.HuffDeflate(&puff_reader, &bit_writer); -} - template <typename T> bool TestExtentsArrayForFuzzer(const vector<T>& extents) { const size_t kMaxArraySize = 100; @@ -114,7 +84,8 @@ void FuzzPuffPatch(const uint8_t* data, size_t size) { } } -struct Environment { +class Environment { + public: Environment() { // To turn off the logging. logging::SetMinLogLevel(logging::LOG_FATAL); @@ -123,13 +94,12 @@ struct Environment { std::cerr.setstate(std::ios_base::failbit); } }; -Environment* env = new Environment(); } // namespace extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - FuzzPuff(data, size); - FuzzHuff(data, size); + static Environment env; + FuzzPuffPatch(data, size); return 0; } |