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 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" 16 17 namespace webrtc { 18 // We decide which header extensions to register by reading four bytes 19 // from the beginning of |data| and interpreting it as a bitmask over 20 // the RTPExtensionType enum. This assert ensures four bytes are enough. 21 static_assert(kRtpExtensionNumberOfExtensions <= 32, 22 "Insufficient bits read to configure all header extensions. Add " 23 "an extra byte and update the switches."); 24 FuzzOneInput(const uint8_t * data,size_t size)25void FuzzOneInput(const uint8_t* data, size_t size) { 26 if (size <= 4) 27 return; 28 29 // Don't use the configuration byte as part of the packet. 30 std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data)); 31 data += 4; 32 size -= 4; 33 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++) { 39 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); 40 if (extensionMask[i]) { 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 43 // parsing so the value of the ID isn't relevant. 44 extensions.RegisterByType(local_id++, extension_type); 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 53