blob: 9e111a80f249337e2d0f93ceb72641031b663310 [file] [log] [blame]
katrielcb86dd872016-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
katrielcb86dd872016-06-23 10:50:3913#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
katrielc9a0de5d2016-07-05 14:20:2414#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
katrielcb86dd872016-06-23 10:50:3915#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
16
17namespace webrtc {
danilchapb7801512017-04-19 09:59:4818// We decide which header extensions to register by reading two bytes
katrielc9a0de5d2016-07-05 14:20:2419// from the beginning of |data| and interpreting it as a bitmask over
danilchapb7801512017-04-19 09:59:4820// the RTPExtensionType enum. This assert ensures two bytes are enough.
21static_assert(kRtpExtensionNumberOfExtensions <= 16,
katrielc9a0de5d2016-07-05 14:20:2422 "Insufficient bits read to configure all header extensions. Add "
23 "an extra byte and update the switches.");
24
katrielcb86dd872016-06-23 10:50:3925void FuzzOneInput(const uint8_t* data, size_t size) {
danilchapb7801512017-04-19 09:59:4826 if (size <= 2)
katrielcb86dd872016-06-23 10:50:3927 return;
28
katrielc9a0de5d2016-07-05 14:20:2429 // Don't use the configuration byte as part of the packet.
danilchapb7801512017-04-19 09:59:4830 std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data));
31 data += 2;
32 size -= 2;
katrielcb86dd872016-06-23 10:50:3933
34 RtpPacketReceived::ExtensionManager extensions;
danilchapb7801512017-04-19 09:59:4835 // Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid.
katrielc9a0de5d2016-07-05 14:20:2436 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.
danilchapb7801512017-04-19 09:59:4842 extensions.RegisterByType(i, extension_type);
katrielcb86dd872016-06-23 10:50:3943 }
44 }
45
46 RTPHeader rtp_header;
47 RtpUtility::RtpHeaderParser rtp_parser(data, size);
48 rtp_parser.Parse(&rtp_header, &extensions);
49}
50} // namespace webrtc