openscreen_message_framer_deserialize_fuzzer.cc 984 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2021 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 <cstddef>
  5. #include <cstdint>
  6. #include "third_party/openscreen/src/cast/common/channel/message_framer.h"
  7. #include "third_party/protobuf/src/google/protobuf/stubs/logging.h"
  8. // Silence logging from the protobuf library.
  9. google::protobuf::LogSilencer log_silencer;
  10. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  11. auto buffer = absl::Span<const uint8_t>(data, size);
  12. size_t bytes_ingested = 0u;
  13. while (bytes_ingested < size) {
  14. openscreen::ErrorOr<
  15. openscreen::cast::message_serialization::DeserializeResult>
  16. result =
  17. openscreen::cast::message_serialization::TryDeserialize(buffer);
  18. if (result.is_error()) {
  19. break;
  20. }
  21. bytes_ingested += result.value().length;
  22. buffer = buffer.subspan(result.value().length);
  23. }
  24. return 0;
  25. }