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

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

Issue 2268183009: H264SPS: Centralize computation of coded size and visible rect. (Closed)
Patch Set: Make sure fuzzing code actually runs. Created 4 years, 3 months 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 | « media/filters/h264_parser.cc ('k') | media/filters/h264_parser_unittest.cc » ('j') | 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 6
7 #include "base/numerics/safe_conversions.h" 7 #include "base/numerics/safe_conversions.h"
8 #include "base/optional.h"
8 #include "media/filters/h264_parser.h" 9 #include "media/filters/h264_parser.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/geometry/size.h"
12
13 static volatile size_t volatile_sink;
9 14
10 // Entry point for LibFuzzer. 15 // Entry point for LibFuzzer.
11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12 if (!size) 17 if (!size)
13 return 0; 18 return 0;
14 19
15 media::H264Parser parser; 20 media::H264Parser parser;
16 parser.SetStream(data, base::checked_cast<off_t>(size)); 21 parser.SetStream(data, base::checked_cast<off_t>(size));
17 22
18 // Parse until the end of stream/unsupported stream/error in stream is 23 // Parse until the end of stream/unsupported stream/error in stream is
19 // found. 24 // found.
20 while (true) { 25 while (true) {
21 media::H264NALU nalu; 26 media::H264NALU nalu;
22 media::H264Parser::Result res = parser.AdvanceToNextNALU(&nalu); 27 media::H264Parser::Result res = parser.AdvanceToNextNALU(&nalu);
23 if (res != media::H264Parser::kOk) 28 if (res != media::H264Parser::kOk)
24 break; 29 break;
25 30
26 switch (nalu.nal_unit_type) { 31 switch (nalu.nal_unit_type) {
27 case media::H264NALU::kIDRSlice: 32 case media::H264NALU::kIDRSlice:
28 case media::H264NALU::kNonIDRSlice: { 33 case media::H264NALU::kNonIDRSlice: {
29 media::H264SliceHeader shdr; 34 media::H264SliceHeader shdr;
30 res = parser.ParseSliceHeader(nalu, &shdr); 35 res = parser.ParseSliceHeader(nalu, &shdr);
31 break; 36 break;
32 } 37 }
33 38
34 case media::H264NALU::kSPS: { 39 case media::H264NALU::kSPS: {
35 int id; 40 int id;
36 res = parser.ParseSPS(&id); 41 res = parser.ParseSPS(&id);
42 if (res != media::H264Parser::kOk)
43 break;
44 const media::H264SPS* sps = parser.GetSPS(id);
45 if (!sps)
46 break;
47 // Also test the SPS helper methods. We make sure that the results are
48 // used so that the calls are not optimized away.
49 base::Optional<gfx::Size> coded_size = sps->GetCodedSize();
50 volatile_sink = coded_size.value_or(gfx::Size()).ToString().length();
51 base::Optional<gfx::Rect> visible_rect = sps->GetVisibleRect();
52 volatile_sink = visible_rect.value_or(gfx::Rect()).ToString().length();
37 break; 53 break;
38 } 54 }
39 55
40 case media::H264NALU::kPPS: { 56 case media::H264NALU::kPPS: {
41 int id; 57 int id;
42 res = parser.ParsePPS(&id); 58 res = parser.ParsePPS(&id);
43 break; 59 break;
44 } 60 }
45 61
46 case media::H264NALU::kSEIMessage: { 62 case media::H264NALU::kSEIMessage: {
47 media::H264SEIMessage sei_msg; 63 media::H264SEIMessage sei_msg;
48 res = parser.ParseSEI(&sei_msg); 64 res = parser.ParseSEI(&sei_msg);
49 break; 65 break;
50 } 66 }
51 67
52 default: 68 default:
53 // Skip any other NALU. 69 // Skip any other NALU.
54 break; 70 break;
55 } 71 }
56 if (res != media::H264Parser::kOk) 72 if (res != media::H264Parser::kOk)
57 break; 73 break;
58 } 74 }
59 75
60 return 0; 76 return 0;
61 } 77 }
OLDNEW
« no previous file with comments | « media/filters/h264_parser.cc ('k') | media/filters/h264_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698