blob: 8ad21e141757d84a3780f035280b5b42c77efa48 [file] [log] [blame]
philipelea142f82017-01-11 02:01:56 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/packet_buffer.h"
12#include "system_wrappers/include/clock.h"
philipel0c87e292018-05-17 16:44:47 +020013#include "test/fuzzers/fuzz_data_helper.h"
philipelea142f82017-01-11 02:01:56 -080014
15namespace webrtc {
philipelea142f82017-01-11 02:01:56 -080016namespace {
17class NullCallback : public video_coding::OnReceivedFrameCallback {
18 void OnReceivedFrame(std::unique_ptr<video_coding::RtpFrameObject> frame) {}
19};
20} // namespace
21
22void FuzzOneInput(const uint8_t* data, size_t size) {
philipelea142f82017-01-11 02:01:56 -080023 VCMPacket packet;
24 NullCallback callback;
25 SimulatedClock clock(0);
26 rtc::scoped_refptr<video_coding::PacketBuffer> packet_buffer(
27 video_coding::PacketBuffer::Create(&clock, 8, 1024, &callback));
philipel0c87e292018-05-17 16:44:47 +020028 test::FuzzDataHelper helper(rtc::ArrayView<const uint8_t>(data, size));
philipelea142f82017-01-11 02:01:56 -080029
philipel32134472018-07-10 11:31:29 +020030 while (helper.BytesLeft()) {
31 // The RTPVideoHeader is a complex type, so overwriting it with random data
32 // will put it in an invalid state. Therefore we save/restore it.
33 uint8_t video_header_backup[sizeof(packet.video_header)];
34 memcpy(&video_header_backup, &packet.video_header,
35 sizeof(packet.video_header));
36
philipelc71cd6c2018-10-03 15:22:51 +020037 uint8_t generic_descriptor_backup[sizeof(packet.generic_descriptor)];
38 memcpy(&generic_descriptor_backup, &packet.generic_descriptor,
39 sizeof(packet.generic_descriptor));
40
philipel0c87e292018-05-17 16:44:47 +020041 helper.CopyTo(&packet);
philipel32134472018-07-10 11:31:29 +020042
43 memcpy(&packet.video_header, &video_header_backup,
44 sizeof(packet.video_header));
45
philipelc71cd6c2018-10-03 15:22:51 +020046 memcpy(&packet.generic_descriptor, &generic_descriptor_backup,
47 sizeof(packet.generic_descriptor));
48
philipel32134472018-07-10 11:31:29 +020049 // The packet buffer owns the payload of the packet.
50 uint8_t payload_size;
51 helper.CopyTo(&payload_size);
52 packet.sizeBytes = payload_size;
53 packet.dataPtr = new uint8_t[payload_size];
54
55 packet_buffer->InsertPacket(&packet);
56 }
philipelea142f82017-01-11 02:01:56 -080057}
58
59} // namespace webrtc