1 // Copyright 2015 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 <stddef.h> 6 #include <stdint.h> 7 8 #include "third_party/snappy/src/snappy-sinksource.h" 9 #include "third_party/snappy/src/snappy.h" 10 11 // Entry point for LibFuzzer. LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)12extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 13 snappy::ByteArraySource src(reinterpret_cast<const char*>(data), size); 14 uint32_t len; 15 // Note: src is invalid after GetUncompressedLength call. 16 if (!snappy::GetUncompressedLength(&src, &len) || (len > 1E6)) { 17 // We have to bail out, to avoid self-crafted decompression bombs. 18 return 0; 19 } 20 21 std::string uncompressed_str; 22 snappy::Uncompress(reinterpret_cast<const char*>(data), size, 23 &uncompressed_str); 24 return 0; 25 } 26