brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 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 | |
Henrik Kjellander | a80c16a | 2017-07-01 16:48:15 +0200 | [diff] [blame] | 13 | #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 14 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 15 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/basictypes.h" |
brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | namespace { |
| 22 | class DummyCallback : public RecoveredPacketReceiver { |
nisse | d2ef314 | 2017-05-11 08:00:58 -0700 | [diff] [blame] | 23 | void OnRecoveredPacket(const uint8_t* packet, size_t length) override {} |
brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 24 | }; |
| 25 | } // namespace |
| 26 | |
| 27 | void FuzzOneInput(const uint8_t* data, size_t size) { |
| 28 | constexpr size_t kMinDataNeeded = 12; |
| 29 | if (size < kMinDataNeeded) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | uint32_t flexfec_ssrc; |
| 34 | memcpy(&flexfec_ssrc, data + 0, 4); |
| 35 | uint16_t flexfec_seq_num; |
| 36 | memcpy(&flexfec_seq_num, data + 4, 2); |
| 37 | uint32_t media_ssrc; |
| 38 | memcpy(&media_ssrc, data + 6, 4); |
| 39 | uint16_t media_seq_num; |
| 40 | memcpy(&media_seq_num, data + 10, 2); |
| 41 | |
| 42 | DummyCallback callback; |
brandtr | 0a4c161 | 2016-11-03 08:18:27 -0700 | [diff] [blame] | 43 | FlexfecReceiver receiver(flexfec_ssrc, media_ssrc, &callback); |
brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 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 | } |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 65 | RtpPacketReceived parsed_packet; |
| 66 | if (parsed_packet.Parse(packet.get(), packet_length)) { |
nisse | 5c29a7a | 2017-02-16 06:52:32 -0800 | [diff] [blame] | 67 | receiver.OnRtpPacket(parsed_packet); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 68 | } |
brandtr | e405d9b | 2016-10-18 01:18:04 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | } // namespace webrtc |