snappy_uncompress_fuzzer.cc 867 B

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