OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <bitset> | 11 #include <bitset> |
12 | 12 |
| 13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
13 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 14 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | |
15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
| 18 // We decide which header extensions to register by reading one byte |
| 19 // from the beginning of |data| and interpreting it as a bitmask over |
| 20 // the RTPExtensionType enum. This assert ensures one byte is enough. |
| 21 static_assert(kRtpExtensionNumberOfExtensions <= 8, |
| 22 "Insufficient bits read to configure all header extensions. Add " |
| 23 "an extra byte and update the switches."); |
| 24 |
18 void FuzzOneInput(const uint8_t* data, size_t size) { | 25 void FuzzOneInput(const uint8_t* data, size_t size) { |
19 if (size <= 1) | 26 if (size <= 1) |
20 return; | 27 return; |
21 | 28 |
22 // We decide which header extensions to register by reading one byte | 29 // Don't use the configuration byte as part of the packet. |
23 // from the beginning of |data| and interpreting it as a bitmask | |
24 // over the RTPExtensionType enum. That byte shouldn't also be part | |
25 // of the packet, so we adjust |data| and |size| to remove it. | |
26 std::bitset<8> extensionMask(data[0]); | 30 std::bitset<8> extensionMask(data[0]); |
27 data++; | 31 data++; |
28 size--; | 32 size--; |
29 | 33 |
30 RtpPacketReceived::ExtensionManager extensions; | 34 RtpPacketReceived::ExtensionManager extensions; |
31 for (int i = 1; i <= kRtpExtensionNumberOfExtensions; i++) { | 35 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { |
32 // Skip i=0 which is kRtpExtensionNone i.e. not an actual extension. | 36 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); |
33 if (extensionMask[i]) { | 37 if (extensionMask[i] && extension_type != kRtpExtensionNone) { |
34 // We use i as the ID; it's used in negotiation so not relevant. | 38 // Extensions are registered with an ID, which you signal to the |
35 extensions.Register(static_cast<RTPExtensionType>(i), i); | 39 // peer so they know what to expect. This code only cares about |
| 40 // parsing so the value of the ID isn't relevant; we use i. |
| 41 extensions.Register(extension_type, i); |
36 } | 42 } |
37 } | 43 } |
38 | 44 |
39 RTPHeader rtp_header; | 45 RTPHeader rtp_header; |
40 RtpUtility::RtpHeaderParser rtp_parser(data, size); | 46 RtpUtility::RtpHeaderParser rtp_parser(data, size); |
41 rtp_parser.Parse(&rtp_header, &extensions); | 47 rtp_parser.Parse(&rtp_header, &extensions); |
42 } | 48 } |
43 } // namespace webrtc | 49 } // namespace webrtc |
OLD | NEW |