blob: fb0f1de2e52af631e04fba18123b51241113422a [file] [log] [blame]
katrielcd4bcdad2016-06-23 03:50:39 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020013#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"
katrielcd4bcdad2016-06-23 03:50:39 -070016
17namespace webrtc {
Johannes Krond6c6f162019-02-21 09:33:14 +010018// We decide which header extensions to register by reading four bytes
katrielc36a321d2016-07-05 07:20:24 -070019// from the beginning of |data| and interpreting it as a bitmask over
Johannes Krond6c6f162019-02-21 09:33:14 +010020// the RTPExtensionType enum. This assert ensures four bytes are enough.
21static_assert(kRtpExtensionNumberOfExtensions <= 32,
katrielc36a321d2016-07-05 07:20:24 -070022 "Insufficient bits read to configure all header extensions. Add "
23 "an extra byte and update the switches.");
24
katrielcd4bcdad2016-06-23 03:50:39 -070025void FuzzOneInput(const uint8_t* data, size_t size) {
Johannes Krond6c6f162019-02-21 09:33:14 +010026 if (size <= 4)
katrielcd4bcdad2016-06-23 03:50:39 -070027 return;
28
katrielc36a321d2016-07-05 07:20:24 -070029 // Don't use the configuration byte as part of the packet.
Johannes Krond6c6f162019-02-21 09:33:14 +010030 std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
31 data += 4;
32 size -= 4;
katrielcd4bcdad2016-06-23 03:50:39 -070033
Johannes Krond6c6f162019-02-21 09:33:14 +010034 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++) {
katrielc36a321d2016-07-05 07:20:24 -070039 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
Johannes Krond6c6f162019-02-21 09:33:14 +010040 if (extensionMask[i]) {
katrielc36a321d2016-07-05 07:20:24 -070041 // 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 Krond6c6f162019-02-21 09:33:14 +010043 // parsing so the value of the ID isn't relevant.
44 extensions.RegisterByType(local_id++, extension_type);
katrielcd4bcdad2016-06-23 03:50:39 -070045 }
46 }
47
48 RTPHeader rtp_header;
49 RtpUtility::RtpHeaderParser rtp_parser(data, size);
50 rtp_parser.Parse(&rtp_header, &extensions);
51}
52} // namespace webrtc