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 | |
Jonathan Metzman | 9f80b97 | 2018-10-05 10:38:13 -0700 | [diff] [blame] | 11 | #include "modules/video_coding/frame_object.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 12 | #include "modules/video_coding/packet_buffer.h" |
| 13 | #include "system_wrappers/include/clock.h" |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 14 | #include "test/fuzzers/fuzz_data_helper.h" |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 17 | namespace { |
Elad Alon | b4643ad | 2019-02-22 11:19:50 +0100 | [diff] [blame] | 18 | class NullCallback : public video_coding::OnAssembledFrameCallback { |
| 19 | void OnAssembledFrame(std::unique_ptr<video_coding::RtpFrameObject> frame) {} |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 20 | }; |
| 21 | } // namespace |
| 22 | |
| 23 | void FuzzOneInput(const uint8_t* data, size_t size) { |
Sam Zackrisson | 2620470 | 2018-10-25 13:46:26 +0200 | [diff] [blame] | 24 | if (size > 200000) { |
| 25 | return; |
| 26 | } |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 27 | VCMPacket packet; |
| 28 | NullCallback callback; |
| 29 | SimulatedClock clock(0); |
Danil Chapovalov | f7457e5 | 2019-09-20 17:57:15 +0200 | [diff] [blame^] | 30 | video_coding::PacketBuffer packet_buffer(&clock, 8, 1024, &callback); |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 31 | test::FuzzDataHelper helper(rtc::ArrayView<const uint8_t>(data, size)); |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 32 | |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 33 | while (helper.BytesLeft()) { |
Chen Xing | 9aa870a | 2019-06-21 10:48:59 +0200 | [diff] [blame] | 34 | // Complex types (e.g. non-POD-like types) can't be bit-wise fuzzed with |
| 35 | // random data or it will put them in an invalid state. We therefore backup |
| 36 | // their byte-patterns before the fuzzing and restore them after. |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 37 | uint8_t video_header_backup[sizeof(packet.video_header)]; |
| 38 | memcpy(&video_header_backup, &packet.video_header, |
| 39 | sizeof(packet.video_header)); |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 40 | uint8_t generic_descriptor_backup[sizeof(packet.generic_descriptor)]; |
| 41 | memcpy(&generic_descriptor_backup, &packet.generic_descriptor, |
| 42 | sizeof(packet.generic_descriptor)); |
Chen Xing | 9aa870a | 2019-06-21 10:48:59 +0200 | [diff] [blame] | 43 | uint8_t packet_info_backup[sizeof(packet.packet_info)]; |
| 44 | memcpy(&packet_info_backup, &packet.packet_info, |
| 45 | sizeof(packet.packet_info)); |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 46 | |
philipel | 0c87e29 | 2018-05-17 16:44:47 +0200 | [diff] [blame] | 47 | helper.CopyTo(&packet); |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 48 | |
| 49 | memcpy(&packet.video_header, &video_header_backup, |
| 50 | sizeof(packet.video_header)); |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 51 | memcpy(&packet.generic_descriptor, &generic_descriptor_backup, |
| 52 | sizeof(packet.generic_descriptor)); |
Chen Xing | 9aa870a | 2019-06-21 10:48:59 +0200 | [diff] [blame] | 53 | memcpy(&packet.packet_info, &packet_info_backup, |
| 54 | sizeof(packet.packet_info)); |
philipel | c71cd6c | 2018-10-03 15:22:51 +0200 | [diff] [blame] | 55 | |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 56 | // The packet buffer owns the payload of the packet. |
| 57 | uint8_t payload_size; |
| 58 | helper.CopyTo(&payload_size); |
| 59 | packet.sizeBytes = payload_size; |
| 60 | packet.dataPtr = new uint8_t[payload_size]; |
| 61 | |
Danil Chapovalov | f7457e5 | 2019-09-20 17:57:15 +0200 | [diff] [blame^] | 62 | packet_buffer.InsertPacket(&packet); |
philipel | 3213447 | 2018-07-10 11:31:29 +0200 | [diff] [blame] | 63 | } |
philipel | ea142f8 | 2017-01-11 02:01:56 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace webrtc |