xref: /aosp_15_r20/external/webrtc/test/fuzzers/congestion_controller_feedback_fuzzer.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
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  */
10 
11 #include "absl/functional/bind_front.h"
12 #include "modules/congestion_controller/include/receive_side_congestion_controller.h"
13 #include "modules/pacing/packet_router.h"
14 #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
15 #include "modules/rtp_rtcp/source/byte_io.h"
16 
17 namespace webrtc {
18 
FuzzOneInput(const uint8_t * data,size_t size)19 void FuzzOneInput(const uint8_t* data, size_t size) {
20   size_t i = 0;
21   if (size < sizeof(int64_t) + sizeof(uint8_t) + sizeof(uint32_t))
22     return;
23   SimulatedClock clock(data[i++]);
24   PacketRouter packet_router;
25   ReceiveSideCongestionController cc(
26       &clock,
27       absl::bind_front(&PacketRouter::SendCombinedRtcpPacket, &packet_router),
28       absl::bind_front(&PacketRouter::SendRemb, &packet_router), nullptr);
29   RTPHeader header;
30   header.ssrc = ByteReader<uint32_t>::ReadBigEndian(&data[i]);
31   i += sizeof(uint32_t);
32   header.extension.hasTransportSequenceNumber = true;
33   int64_t arrival_time_ms = std::min<int64_t>(
34       std::max<int64_t>(ByteReader<int64_t>::ReadBigEndian(&data[i]), 0),
35       std::numeric_limits<int64_t>::max() / 2);
36   i += sizeof(int64_t);
37   const size_t kMinPacketSize =
38       sizeof(size_t) + sizeof(uint16_t) + sizeof(uint8_t);
39   while (i + kMinPacketSize < size) {
40     size_t payload_size = ByteReader<size_t>::ReadBigEndian(&data[i]) % 1500;
41     i += sizeof(size_t);
42     header.extension.transportSequenceNumber =
43         ByteReader<uint16_t>::ReadBigEndian(&data[i]);
44     i += sizeof(uint16_t);
45     cc.OnReceivedPacket(arrival_time_ms, payload_size, header);
46     clock.AdvanceTimeMilliseconds(5);
47     arrival_time_ms += ByteReader<uint8_t>::ReadBigEndian(&data[i]);
48     i += sizeof(uint8_t);
49     cc.MaybeProcess();
50   }
51 }
52 }  // namespace webrtc
53