philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/packet_buffer.h" |
| 12 | #include "system_wrappers/include/clock.h" |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 13 | #include "test/fuzzers/fuzz_data_helper.h" |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 16 | namespace { |
| 17 | class NullCallback : public video_coding::OnReceivedFrameCallback { |
| 18 | void OnReceivedFrame(std::unique_ptr<video_coding::RtpFrameObject> frame) {} |
| 19 | }; |
| 20 | } // namespace |
| 21 | |
| 22 | void FuzzOneInput(const uint8_t* data, size_t size) { |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 23 | 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)); |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 28 | test::FuzzDataHelper helper(rtc::ArrayView<const uint8_t>(data, size)); |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 29 | |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 30 | 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 | |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 37 | uint8_t generic_descriptor_backup[sizeof(packet.generic_descriptor)]; |
| 38 | memcpy(&generic_descriptor_backup, &packet.generic_descriptor, |
| 39 | sizeof(packet.generic_descriptor)); |
| 40 | |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 41 | helper.CopyTo(&packet); |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 42 | |
| 43 | memcpy(&packet.video_header, &video_header_backup, |
| 44 | sizeof(packet.video_header)); |
| 45 | |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 46 | memcpy(&packet.generic_descriptor, &generic_descriptor_backup, |
| 47 | sizeof(packet.generic_descriptor)); |
| 48 | |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 49 | // 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 | } |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace webrtc |