• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium 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 <stddef.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include <cassert>
9 #include <vector>
10 
11 #include "third_party/zlib/zlib.h"
12 
13 static Bytef buffer[256 * 1024] = {0};
14 
15 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17   // We need to strip the 'const' for zlib
18   std::vector<unsigned char> input_buffer{data, data+size};
19 
20   uLongf buffer_length = static_cast<uLongf>(sizeof(buffer));
21 
22   z_stream stream;
23   stream.next_in = input_buffer.data();
24   stream.avail_in = size;
25   stream.total_in = size;
26   stream.next_out = buffer;
27   stream.avail_out = buffer_length;
28   stream.total_out = buffer_length;
29   stream.zalloc = Z_NULL;
30   stream.zfree = Z_NULL;
31 
32   if (Z_OK != inflateInit(&stream)) {
33     inflateEnd(&stream);
34     assert(false);
35   }
36 
37   inflate(&stream, Z_NO_FLUSH);
38   inflateEnd(&stream);
39 
40   return 0;
41 }
42