OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 <algorithm> |
| 12 |
| 13 #include "webrtc/base/basictypes.h" |
| 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 15 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 17 |
| 18 namespace webrtc { |
| 19 |
| 20 namespace { |
| 21 class DummyCallback : public RecoveredPacketReceiver { |
| 22 bool OnRecoveredPacket(const uint8_t* packet, size_t length) { return true; } |
| 23 }; |
| 24 } // namespace |
| 25 |
| 26 void FuzzOneInput(const uint8_t* data, size_t size) { |
| 27 constexpr size_t kMinDataNeeded = 12; |
| 28 if (size < kMinDataNeeded) { |
| 29 return; |
| 30 } |
| 31 |
| 32 uint32_t flexfec_ssrc; |
| 33 memcpy(&flexfec_ssrc, data + 0, 4); |
| 34 uint16_t flexfec_seq_num; |
| 35 memcpy(&flexfec_seq_num, data + 4, 2); |
| 36 uint32_t media_ssrc; |
| 37 memcpy(&media_ssrc, data + 6, 4); |
| 38 uint16_t media_seq_num; |
| 39 memcpy(&media_seq_num, data + 10, 2); |
| 40 |
| 41 DummyCallback callback; |
| 42 std::unique_ptr<FlexfecReceiver> receiver = |
| 43 FlexfecReceiver::Create(flexfec_ssrc, media_ssrc, &callback); |
| 44 |
| 45 std::unique_ptr<uint8_t[]> packet; |
| 46 size_t packet_length; |
| 47 size_t i = kMinDataNeeded; |
| 48 while (i < size) { |
| 49 packet_length = kRtpHeaderSize + data[i++]; |
| 50 packet = std::unique_ptr<uint8_t[]>(new uint8_t[packet_length]); |
| 51 if (i + packet_length >= size) { |
| 52 break; |
| 53 } |
| 54 memcpy(packet.get(), data + i, packet_length); |
| 55 i += packet_length; |
| 56 if (i < size && data[i++] % 2 == 0) { |
| 57 // Simulate FlexFEC packet. |
| 58 ByteWriter<uint16_t>::WriteBigEndian(packet.get() + 2, flexfec_seq_num++); |
| 59 ByteWriter<uint32_t>::WriteBigEndian(packet.get() + 8, flexfec_ssrc); |
| 60 } else { |
| 61 // Simulate media packet. |
| 62 ByteWriter<uint16_t>::WriteBigEndian(packet.get() + 2, media_seq_num++); |
| 63 ByteWriter<uint32_t>::WriteBigEndian(packet.get() + 8, media_ssrc); |
| 64 } |
| 65 receiver->AddAndProcessReceivedPacket(packet.get(), packet_length); |
| 66 } |
| 67 } |
| 68 |
| 69 } // namespace webrtc |
OLD | NEW |