• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors
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 "third_party/snappy/src/snappy.h"
6 
7 #define FUZZING_ASSERT(condition)                                      \
8   if (!(condition)) {                                                  \
9     fprintf(stderr, "%s\n", "Fuzzing Assertion Failure: " #condition); \
10     abort();                                                           \
11   }
12 
13 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
15   const char* uncompressed = reinterpret_cast<const char*>(data);
16   std::string compressed;
17   snappy::Compress(uncompressed, size, &compressed);
18   FUZZING_ASSERT(
19       snappy::IsValidCompressedBuffer(compressed.data(), compressed.size()));
20 
21   std::string uncompressed_after_compress;
22   FUZZING_ASSERT(snappy::Uncompress(compressed.data(), compressed.size(),
23                                     &uncompressed_after_compress));
24   FUZZING_ASSERT(uncompressed_after_compress ==
25                  std::string(uncompressed, size));
26 
27   return 0;
28 }
29