Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: media/filters/vpx_video_decoder_fuzzertest.cc

Issue 2324843004: Generate more valid configurations in media_vpx_video_decoder_fuzzer. (Closed)
Patch Set: Rebase + change the description. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <random> 8 #include <random>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
49 std::mt19937_64 rng; 49 std::mt19937_64 rng;
50 50
51 { // Seed rng from data. 51 { // Seed rng from data.
52 std::string str = std::string(reinterpret_cast<const char*>(data), size); 52 std::string str = std::string(reinterpret_cast<const char*>(data), size);
53 std::size_t data_hash = std::hash<std::string>()(str); 53 std::size_t data_hash = std::hash<std::string>()(str);
54 rng.seed(data_hash); 54 rng.seed(data_hash);
55 } 55 }
56 56
57 // Compute randomized constants. Put all rng() usages here. 57 // Compute randomized constants. Put all rng() usages here.
58 auto codec = static_cast<VideoCodec>(rng() % kVideoCodecMax); 58 // Use only values that pass DCHECK in VpxVideoDecoder::ConfigureDecoder().
59 VideoCodec codec;
60 VideoPixelFormat pixel_format;
61 if (rng() & 1) {
62 codec = kCodecVP8;
63 // PIXEL_FORMAT_YV12 disabled for kCodecVP8 on Linux.
64 pixel_format = PIXEL_FORMAT_YV12A;
65 } else {
66 codec = kCodecVP9;
67 switch (rng() % 3) {
68 case 0:
69 pixel_format = PIXEL_FORMAT_YV12;
70 break;
71 case 1:
72 pixel_format = PIXEL_FORMAT_YV12A;
73 break;
74 case 2:
75 pixel_format = PIXEL_FORMAT_YV24;
76 break;
77 default:
78 return 0;
79 }
80 }
81
59 auto profile = 82 auto profile =
60 static_cast<VideoCodecProfile>(rng() % VIDEO_CODEC_PROFILE_MAX); 83 static_cast<VideoCodecProfile>(rng() % VIDEO_CODEC_PROFILE_MAX);
61 auto pixel_format = static_cast<VideoPixelFormat>(rng() % PIXEL_FORMAT_MAX);
62 auto color_space = static_cast<ColorSpace>(rng() % COLOR_SPACE_MAX); 84 auto color_space = static_cast<ColorSpace>(rng() % COLOR_SPACE_MAX);
63 auto coded_size = gfx::Size(rng() % 128, rng() % 128); 85 auto coded_size = gfx::Size(1 + (rng() % 127), 1 + (rng() % 127));
64 auto visible_rect = gfx::Rect(rng() % 128, rng() % 128); 86 auto visible_rect = gfx::Rect(coded_size);
65 auto natural_size = gfx::Size(rng() % 128, rng() % 128); 87 auto natural_size = gfx::Size(1 + (rng() % 127), 1 + (rng() % 127));
66 88
67 VideoDecoderConfig config(codec, profile, pixel_format, color_space, 89 VideoDecoderConfig config(codec, profile, pixel_format, color_space,
68 coded_size, visible_rect, natural_size, 90 coded_size, visible_rect, natural_size,
69 EmptyExtraData(), Unencrypted()); 91 EmptyExtraData(), Unencrypted());
70 92
93 if (!config.IsValidConfig())
94 return 0;
95
71 VpxVideoDecoder decoder; 96 VpxVideoDecoder decoder;
72 97
73 { 98 {
74 base::RunLoop run_loop; 99 base::RunLoop run_loop;
75 bool success = false; 100 bool success = false;
76 decoder.Initialize( 101 decoder.Initialize(
77 config, true /* low_delay */, nullptr /* cdm_context */, 102 config, true /* low_delay */, nullptr /* cdm_context */,
78 base::Bind(&OnInitDone, run_loop.QuitClosure(), &success), 103 base::Bind(&OnInitDone, run_loop.QuitClosure(), &success),
79 base::Bind(&OnOutputComplete)); 104 base::Bind(&OnOutputComplete));
80 run_loop.Run(); 105 run_loop.Run();
81 if (!success) 106 if (!success)
82 return 0; 107 return 0;
83 } 108 }
84 109
85 { 110 {
86 base::RunLoop run_loop; 111 base::RunLoop run_loop;
87 auto buffer = DecoderBuffer::CopyFrom(data, size); 112 auto buffer = DecoderBuffer::CopyFrom(data, size);
88 decoder.Decode(buffer, 113 decoder.Decode(buffer,
89 base::Bind(&OnDecodeComplete, run_loop.QuitClosure())); 114 base::Bind(&OnDecodeComplete, run_loop.QuitClosure()));
90 run_loop.Run(); 115 run_loop.Run();
91 } 116 }
92 117
93 return 0; 118 return 0;
94 } 119 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698