• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <vector>
6 
7 #include "base/logging.h"
8 #include "brillo/test_helpers.h"
9 
10 #include "puffin/src/bit_reader.h"
11 #include "puffin/src/include/puffin/common.h"
12 #include "puffin/src/include/puffin/puffer.h"
13 #include "puffin/src/puff_writer.h"
14 
15 using puffin::BitExtent;
16 using puffin::Buffer;
17 using puffin::BufferBitReader;
18 using puffin::BufferPuffWriter;
19 using puffin::Puffer;
20 using std::vector;
21 
22 namespace {
FuzzPuff(const uint8_t * data,size_t size)23 void FuzzPuff(const uint8_t* data, size_t size) {
24   BufferBitReader bit_reader(data, size);
25   Buffer puff_buffer(size * 2);
26   BufferPuffWriter puff_writer(puff_buffer.data(), puff_buffer.size());
27   vector<BitExtent> bit_extents;
28   Puffer puffer;
29   puffer.PuffDeflate(&bit_reader, &puff_writer, &bit_extents);
30 }
31 
32 class Environment {
33  public:
Environment()34   Environment() {
35     // To turn off the logging.
36     logging::SetMinLogLevel(logging::LOG_FATAL);
37   }
38 };
39 
40 }  // namespace
41 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)42 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
43   static Environment env;
44 
45   FuzzPuff(data, size);
46   return 0;
47 }
48