Chromium Code Reviews| 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 if (size < 12) { | |
|
stefan-webrtc
2016/10/05 14:48:26
Make 12 a named constant. Or maybe we should rando
brandtr
2016/10/05 15:00:39
Done.
The three literal 12's here signified diffe
| |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 uint32_t flexfec_ssrc; | |
| 32 memcpy(&flexfec_ssrc, data + 0, 4); | |
| 33 uint16_t flexfec_seq_num; | |
| 34 memcpy(&flexfec_seq_num, data + 4, 2); | |
| 35 uint32_t media_ssrc; | |
| 36 memcpy(&media_ssrc, data + 6, 4); | |
| 37 uint16_t media_seq_num; | |
| 38 memcpy(&media_seq_num, data + 10, 2); | |
| 39 | |
| 40 DummyCallback callback; | |
| 41 std::unique_ptr<FlexfecReceiver> receiver = | |
| 42 FlexfecReceiver::Create(flexfec_ssrc, media_ssrc, &callback); | |
| 43 | |
| 44 std::unique_ptr<uint8_t[]> packet; | |
| 45 size_t packet_length; | |
| 46 size_t i = 12; | |
| 47 while (i < size) { | |
| 48 packet_length = 12 + data[i++]; // RTP header plus payload. | |
|
brandtr
2016/10/05 15:00:39
I add the minimum RTP header size here to eliminat
| |
| 49 packet = std::unique_ptr<uint8_t[]>(new uint8_t[packet_length]); | |
| 50 if (i + packet_length >= size) { | |
| 51 break; | |
| 52 } | |
| 53 memcpy(packet.get(), data + i, packet_length); | |
| 54 i += packet_length; | |
| 55 if (i < size && data[i++] % 2 == 0) { | |
| 56 // Simulate FlexFEC packet. | |
| 57 ByteWriter<uint16_t>::WriteBigEndian(packet.get() + 2, flexfec_seq_num++); | |
| 58 ByteWriter<uint32_t>::WriteBigEndian(packet.get() + 8, flexfec_ssrc); | |
| 59 } else { | |
| 60 // Simulate media packet. | |
| 61 ByteWriter<uint16_t>::WriteBigEndian(packet.get() + 2, media_seq_num++); | |
| 62 ByteWriter<uint32_t>::WriteBigEndian(packet.get() + 8, media_ssrc); | |
| 63 } | |
| 64 receiver->AddReceivedPacket(packet.get(), packet_length); | |
| 65 } | |
| 66 receiver->ProcessReceivedPackets(); | |
| 67 } | |
| 68 | |
| 69 } // namespace webrtc | |
| OLD | NEW |