1 /* 2 * Copyright (c) 2021 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 "api/array_view.h" 12 #include "api/video/encoded_frame.h" 13 #include "api/video/frame_buffer.h" 14 #include "rtc_base/numerics/sequence_number_util.h" 15 #include "test/fuzzers/fuzz_data_helper.h" 16 #include "test/scoped_key_value_config.h" 17 18 namespace webrtc { 19 namespace { 20 class FuzzyFrameObject : public EncodedFrame { 21 public: ReceivedTime() const22 int64_t ReceivedTime() const override { return 0; } RenderTime() const23 int64_t RenderTime() const override { return 0; } 24 }; 25 26 constexpr int kFrameIdLength = 1 << 15; 27 28 } // namespace 29 FuzzOneInput(const uint8_t * data,size_t size)30void FuzzOneInput(const uint8_t* data, size_t size) { 31 if (size > 10000) { 32 return; 33 } 34 35 test::ScopedKeyValueConfig field_trials; 36 FrameBuffer buffer(/*max_frame_slots=*/100, /*max_decode_history=*/1000, 37 field_trials); 38 test::FuzzDataHelper helper(rtc::MakeArrayView(data, size)); 39 SeqNumUnwrapper<uint16_t, kFrameIdLength> unwrapper; 40 41 while (helper.BytesLeft() > 0) { 42 int action = helper.ReadOrDefaultValue<uint8_t>(0) % 6; 43 44 switch (action) { 45 case 0: { 46 buffer.LastContinuousFrameId(); 47 break; 48 } 49 case 1: { 50 buffer.LastContinuousTemporalUnitFrameId(); 51 break; 52 } 53 case 2: { 54 buffer.DecodableTemporalUnitsInfo(); 55 break; 56 } 57 case 3: { 58 buffer.ExtractNextDecodableTemporalUnit(); 59 break; 60 } 61 case 4: { 62 buffer.DropNextDecodableTemporalUnit(); 63 break; 64 } 65 case 5: { 66 auto frame = std::make_unique<FuzzyFrameObject>(); 67 frame->SetTimestamp(helper.ReadOrDefaultValue<uint32_t>(0)); 68 int64_t wire_id = 69 helper.ReadOrDefaultValue<uint16_t>(0) & (kFrameIdLength - 1); 70 frame->SetId(unwrapper.Unwrap(wire_id)); 71 frame->is_last_spatial_layer = helper.ReadOrDefaultValue<bool>(false); 72 73 frame->num_references = helper.ReadOrDefaultValue<uint8_t>(0) % 74 EncodedFrame::kMaxFrameReferences; 75 76 for (uint8_t i = 0; i < frame->num_references; ++i) { 77 frame->references[i] = helper.ReadOrDefaultValue<int64_t>(0); 78 } 79 80 buffer.InsertFrame(std::move(frame)); 81 break; 82 } 83 } 84 } 85 } 86 87 } // namespace webrtc 88