1 /*
2  *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include <algorithm>
15 #include <memory>
16 #include <string>
17 
18 #include "test/rtp_header_parser.h"
19 
20 namespace webrtc {
21 
FuzzOneInput(const uint8_t * data,size_t size)22 void FuzzOneInput(const uint8_t* data, size_t size) {
23   RtpHeaderParser::IsRtcp(data, size);
24   RtpHeaderParser::GetSsrc(data, size);
25   RTPHeader rtp_header;
26 
27   std::unique_ptr<RtpHeaderParser> rtp_header_parser(
28       RtpHeaderParser::CreateForTest());
29 
30   rtp_header_parser->Parse(data, size, &rtp_header);
31   for (int i = 1; i < kRtpExtensionNumberOfExtensions; ++i) {
32     if (size > 0 && i >= data[size - 1]) {
33       RTPExtensionType add_extension = static_cast<RTPExtensionType>(i);
34       rtp_header_parser->RegisterRtpHeaderExtension(add_extension, i);
35     }
36   }
37   rtp_header_parser->Parse(data, size, &rtp_header);
38 
39   for (int i = 1; i < kRtpExtensionNumberOfExtensions; ++i) {
40     if (size > 1 && i >= data[size - 2]) {
41       RTPExtensionType remove_extension = static_cast<RTPExtensionType>(i);
42       rtp_header_parser->DeregisterRtpHeaderExtension(remove_extension);
43     }
44   }
45   rtp_header_parser->Parse(data, size, &rtp_header);
46 }
47 
48 }  // namespace webrtc
49