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/include/rtp_rtcp_defines.h" |
14 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 14 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.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 | 18 // We decide which header extensions to register by reading two bytes |
19 // from the beginning of |data| and interpreting it as a bitmask over | 19 // from the beginning of |data| and interpreting it as a bitmask over |
20 // the RTPExtensionType enum. This assert ensures one byte is enough. | 20 // the RTPExtensionType enum. This assert ensures two bytes are enough. |
21 static_assert(kRtpExtensionNumberOfExtensions <= 8, | 21 static_assert(kRtpExtensionNumberOfExtensions <= 16, |
22 "Insufficient bits read to configure all header extensions. Add " | 22 "Insufficient bits read to configure all header extensions. Add " |
23 "an extra byte and update the switches."); | 23 "an extra byte and update the switches."); |
24 | 24 |
25 void FuzzOneInput(const uint8_t* data, size_t size) { | 25 void FuzzOneInput(const uint8_t* data, size_t size) { |
26 if (size <= 1) | 26 if (size <= 2) |
27 return; | 27 return; |
28 | 28 |
29 // Don't use the configuration byte as part of the packet. | 29 // Don't use the configuration byte as part of the packet. |
30 std::bitset<8> extensionMask(data[0]); | 30 std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data)); |
31 data++; | 31 data += 2; |
32 size--; | 32 size -= 2; |
33 | 33 |
34 RtpPacketReceived::ExtensionManager extensions; | 34 RtpPacketReceived::ExtensionManager extensions; |
| 35 // Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid. |
35 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { | 36 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { |
36 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); | 37 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); |
37 if (extensionMask[i] && extension_type != kRtpExtensionNone) { | 38 if (extensionMask[i] && extension_type != kRtpExtensionNone) { |
38 // Extensions are registered with an ID, which you signal to the | 39 // Extensions are registered with an ID, which you signal to the |
39 // peer so they know what to expect. This code only cares about | 40 // 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 // parsing so the value of the ID isn't relevant; we use i. |
41 extensions.Register(extension_type, i); | 42 extensions.RegisterByType(i, extension_type); |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 RTPHeader rtp_header; | 46 RTPHeader rtp_header; |
46 RtpUtility::RtpHeaderParser rtp_parser(data, size); | 47 RtpUtility::RtpHeaderParser rtp_parser(data, size); |
47 rtp_parser.Parse(&rtp_header, &extensions); | 48 rtp_parser.Parse(&rtp_header, &extensions); |
48 } | 49 } |
49 } // namespace webrtc | 50 } // namespace webrtc |
OLD | NEW |