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