aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/zopfli/zopfli_compress_fuzzer.cc
diff options
context:
space:
mode:
authorGravatar Google AutoFuzz Team <security-tps@google.com>2019-08-02 00:37:55 +0200
committerGravatar Max Moroz <mmoroz@chromium.org>2019-08-01 15:37:55 -0700
commit0073eebe041629978a8c1591e90b729076c02d4d (patch)
tree911f14e22289d15b8c0901643c7eb6b35c861f51 /projects/zopfli/zopfli_compress_fuzzer.cc
parentfc4c02825eebbd2fdadb3b58d8f519ac3b547821 (diff)
[zopfli] Add zopfli as a starting point (#2631)
* add zopfli * added primary contact * update zopfli files * removed unnecessary comments * pushed new version of target * added FuzzedDataProvider
Diffstat (limited to 'projects/zopfli/zopfli_compress_fuzzer.cc')
-rw-r--r--projects/zopfli/zopfli_compress_fuzzer.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/projects/zopfli/zopfli_compress_fuzzer.cc b/projects/zopfli/zopfli_compress_fuzzer.cc
new file mode 100644
index 00000000..1edd8144
--- /dev/null
+++ b/projects/zopfli/zopfli_compress_fuzzer.cc
@@ -0,0 +1,45 @@
+// Copyright 2019 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <cstddef>
+#include <cstdint>
+#include <cstdlib>
+#include <string>
+
+#include "zopfli.h"
+#include "FuzzedDataProvider.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ FuzzedDataProvider stream(data, size);
+
+ ZopfliOptions options;
+ ZopfliInitOptions(&options);
+
+ const ZopfliFormat format = stream.PickValueInArray(
+ {ZOPFLI_FORMAT_GZIP, ZOPFLI_FORMAT_ZLIB, ZOPFLI_FORMAT_DEFLATE});
+
+ unsigned char* outbuf = nullptr;
+ size_t outsize = 0;
+ std::vector<unsigned char> input =
+ stream.ConsumeRemainingBytes<unsigned char>();
+
+ ZopfliCompress(&options, format, input.data(), input.size(), &outbuf,
+ &outsize);
+
+ if (outbuf != nullptr) {
+ free(outbuf);
+ }
+
+ return 0;
+}