vp9_parser_fuzzertest.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2016 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 "base/logging.h"
  7. #include "base/numerics/safe_conversions.h"
  8. #include "media/filters/ivf_parser.h"
  9. #include "media/filters/vp9_parser.h"
  10. struct Environment {
  11. Environment() {
  12. // Disable noisy logging as per "libFuzzer in Chrome" documentation:
  13. // testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging.
  14. logging::SetMinLogLevel(logging::LOG_FATAL);
  15. }
  16. };
  17. Environment* env = new Environment();
  18. // Entry point for LibFuzzer.
  19. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  20. std::string str = std::string(reinterpret_cast<const char*>(data), size);
  21. std::size_t data_hash = std::hash<std::string>()(str);
  22. const uint8_t* ivf_payload = nullptr;
  23. media::IvfParser ivf_parser;
  24. media::IvfFileHeader ivf_file_header;
  25. media::IvfFrameHeader ivf_frame_header;
  26. if (!ivf_parser.Initialize(data, size, &ivf_file_header))
  27. return 0;
  28. media::Vp9Parser vp9_parser(data_hash % 2 == 1);
  29. // Parse until the end of stream/unsupported stream/error in stream is found.
  30. while (ivf_parser.ParseNextFrame(&ivf_frame_header, &ivf_payload)) {
  31. media::Vp9FrameHeader vp9_frame_header;
  32. vp9_parser.SetStream(ivf_payload, ivf_frame_header.frame_size, nullptr);
  33. // TODO(kcwu): further fuzzing the case of Vp9Parser::kAwaitingRefresh.
  34. std::unique_ptr<media::DecryptConfig> null_config;
  35. gfx::Size allocate_size;
  36. while (vp9_parser.ParseNextFrame(&vp9_frame_header, &allocate_size,
  37. &null_config) == media::Vp9Parser::kOk) {
  38. // Repeat until all frames processed.
  39. }
  40. }
  41. return 0;
  42. }