blob: 914a8fb9494bc2e701d658ec5c1e55414b6a0586 [file] [log] [blame]
katrielcd4bcdad2016-06-23 10:50:391/*
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
katrielcd4bcdad2016-06-23 10:50:3913#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
katrielc36a321d2016-07-05 14:20:2414#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
katrielcd4bcdad2016-06-23 10:50:3915#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
16
17namespace webrtc {
katrielc36a321d2016-07-05 14:20:2418// 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.
21static_assert(kRtpExtensionNumberOfExtensions <= 8,
22 "Insufficient bits read to configure all header extensions. Add "
23 "an extra byte and update the switches.");
24
katrielcd4bcdad2016-06-23 10:50:3925void FuzzOneInput(const uint8_t* data, size_t size) {
26 if (size <= 1)
27 return;
28
katrielc36a321d2016-07-05 14:20:2429 // Don't use the configuration byte as part of the packet.
katrielcd4bcdad2016-06-23 10:50:3930 std::bitset<8> extensionMask(data[0]);
31 data++;
32 size--;
33
34 RtpPacketReceived::ExtensionManager extensions;
katrielc36a321d2016-07-05 14:20:2435 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) {
36 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
37 if (extensionMask[i] && extension_type != kRtpExtensionNone) {
38 // 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 // parsing so the value of the ID isn't relevant; we use i.
41 extensions.Register(extension_type, i);
katrielcd4bcdad2016-06-23 10:50:3942 }
43 }
44
45 RTPHeader rtp_header;
46 RtpUtility::RtpHeaderParser rtp_parser(data, size);
47 rtp_parser.Parse(&rtp_header, &extensions);
48}
49} // namespace webrtc