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