blob: 96778209f7f91cc5b4b7fa961b775e95ddc675c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <cassert>
#include <vector>
#include "zlib.h"
static Bytef buffer[256 * 1024] = {0};
// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// We need to strip the 'const' for zlib.
std::vector<unsigned char> input_buffer{data, data + size};
uLongf buffer_length = static_cast<uLongf>(sizeof(buffer));
z_stream stream;
stream.next_in = input_buffer.data();
stream.avail_in = size;
stream.total_in = size;
stream.next_out = buffer;
stream.avail_out = buffer_length;
stream.total_out = buffer_length;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
if (Z_OK != deflateInit(&stream, Z_DEFAULT_COMPRESSION)) {
deflateEnd(&stream);
assert(false);
}
auto deflate_set_dictionary_result =
deflateSetDictionary(&stream, data, size);
deflateEnd(&stream);
if (Z_OK != deflate_set_dictionary_result)
assert(false);
return 0;
}
|