xref: /aosp_15_r20/external/webrtc/test/fuzzers/packet_buffer_fuzzer.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2017 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 <memory>
12 #include <utility>
13 
14 #include "modules/video_coding/frame_object.h"
15 #include "modules/video_coding/packet_buffer.h"
16 #include "test/fuzzers/fuzz_data_helper.h"
17 
18 namespace webrtc {
19 
IgnoreResult(video_coding::PacketBuffer::InsertResult result)20 void IgnoreResult(video_coding::PacketBuffer::InsertResult result) {}
21 
FuzzOneInput(const uint8_t * data,size_t size)22 void FuzzOneInput(const uint8_t* data, size_t size) {
23   if (size > 200000) {
24     return;
25   }
26   video_coding::PacketBuffer packet_buffer(8, 1024);
27   test::FuzzDataHelper helper(rtc::ArrayView<const uint8_t>(data, size));
28 
29   while (helper.BytesLeft()) {
30     auto packet = std::make_unique<video_coding::PacketBuffer::Packet>();
31     // Fuzz POD members of the packet.
32     helper.CopyTo(&packet->marker_bit);
33     helper.CopyTo(&packet->payload_type);
34     helper.CopyTo(&packet->seq_num);
35     helper.CopyTo(&packet->timestamp);
36     helper.CopyTo(&packet->times_nacked);
37 
38     // Fuzz non-POD member of the packet.
39     packet->video_payload.SetSize(helper.ReadOrDefaultValue<uint8_t>(0));
40     // TODO(danilchap): Fuzz other non-POD members of the `packet`.
41 
42     IgnoreResult(packet_buffer.InsertPacket(std::move(packet)));
43   }
44 }
45 
46 }  // namespace webrtc
47