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