blob: 43d9450918d9a313dd5e65b76fd564afc96403c2 [file] [log] [blame]
Stefan Holmer4c1093b2015-12-11 17:25:451/*
2 * Copyright (c) 2015 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 */
kwibergbfefb032016-05-01 21:53:4610
11#include <memory>
12
Ying Wang6b33e602018-07-02 15:28:0713#include "modules/include/module_common_types_public.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "modules/rtp_rtcp/source/byte_io.h"
15#include "modules/rtp_rtcp/source/fec_test_helper.h"
16#include "modules/rtp_rtcp/source/ulpfec_generator.h"
17#include "rtc_base/checks.h"
Ilya Nikolaevskiya5d952f2019-09-03 09:07:3718#include "rtc_base/copy_on_write_buffer.h"
Erik Språngf87536c2020-03-05 09:14:0419#include "system_wrappers/include/clock.h"
Stefan Holmer4c1093b2015-12-11 17:25:4520
21namespace webrtc {
22
brandtrece4aba2016-09-21 06:16:2823namespace {
24constexpr uint8_t kFecPayloadType = 96;
25constexpr uint8_t kRedPayloadType = 97;
26} // namespace
27
Stefan Holmer4c1093b2015-12-11 17:25:4528void FuzzOneInput(const uint8_t* data, size_t size) {
Erik Språngf87536c2020-03-05 09:14:0429 SimulatedClock clock(1);
30 UlpfecGenerator generator(kRedPayloadType, kFecPayloadType, &clock);
Stefan Holmer4c1093b2015-12-11 17:25:4531 size_t i = 0;
32 if (size < 4)
33 return;
Peter Boströmd6b9d772016-04-26 22:18:4134 FecProtectionParams params = {
35 data[i++] % 128, static_cast<int>(data[i++] % 10), kFecMaskBursty};
Erik Språngf87536c2020-03-05 09:14:0436 generator.SetProtectionParameters(params, params);
Stefan Holmer4c1093b2015-12-11 17:25:4537 uint16_t seq_num = data[i++];
Ying Wang6a9bd742018-06-15 12:54:1638 uint16_t prev_seq_num = 0;
Stefan Holmer4c1093b2015-12-11 17:25:4539 while (i + 3 < size) {
40 size_t rtp_header_length = data[i++] % 10 + 12;
41 size_t payload_size = data[i++] % 10;
42 if (i + payload_size + rtp_header_length + 2 > size)
43 break;
Ilya Nikolaevskiya5d952f2019-09-03 09:07:3744 rtc::CopyOnWriteBuffer packet(&data[i], payload_size + rtp_header_length);
45 packet.EnsureCapacity(IP_PACKET_SIZE);
Erik Språngf87536c2020-03-05 09:14:0446 // Write a valid parsable header (version = 2, no padding, no extensions,
47 // no CSRCs).
Danil Chapovalova7820222021-01-12 10:44:0548 ByteWriter<uint8_t>::WriteBigEndian(packet.MutableData(), 2 << 6);
Ying Wang6a9bd742018-06-15 12:54:1649 // Make sure sequence numbers are increasing.
Danil Chapovalova7820222021-01-12 10:44:0550 ByteWriter<uint16_t>::WriteBigEndian(packet.MutableData() + 2, seq_num++);
Stefan Holmer4c1093b2015-12-11 17:25:4551 i += payload_size + rtp_header_length;
Peter Boströmf5b804b2016-01-29 15:26:4352 const bool protect = data[i++] % 2 == 1;
Ying Wang6a9bd742018-06-15 12:54:1653
54 // Check the sequence numbers are monotonic. In rare case the packets number
55 // may loop around and in the same FEC-protected group the packet sequence
56 // number became out of order.
Ying Wang6b33e602018-07-02 15:28:0757 if (protect && IsNewerSequenceNumber(seq_num, prev_seq_num) &&
58 seq_num < prev_seq_num + kUlpfecMaxMediaPackets) {
Erik Språngf87536c2020-03-05 09:14:0459 RtpPacketToSend rtp_packet(nullptr);
60 // Check that we actually have a parsable packet, we want to fuzz FEC
61 // logic, not RTP header parsing.
62 RTC_CHECK(rtp_packet.Parse(packet));
63 generator.AddPacketAndGenerateFec(rtp_packet);
Ying Wang6a9bd742018-06-15 12:54:1664 prev_seq_num = seq_num;
Stefan Holmer4c1093b2015-12-11 17:25:4565 }
Erik Språngf87536c2020-03-05 09:14:0466
67 generator.GetFecPackets();
Stefan Holmer4c1093b2015-12-11 17:25:4568 }
69}
70} // namespace webrtc