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/array_view.h" | |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | |
16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | |
17 | |
18 namespace webrtc { | |
19 | |
20 namespace { | |
21 | |
22 using TransportFeedback = rtcp::TransportFeedback; | |
23 | |
24 class FuzzTransportFeedback final : public rtcp::TransportFeedbackInterface { | |
25 public: | |
26 explicit FuzzTransportFeedback(rtc::ArrayView<const uint8_t> data) | |
27 : data_(data), ended_(false), data_idx_(0) { | |
28 ParseNextTransportFeedback(); | |
29 } | |
30 | |
31 uint16_t GetBaseSequence() const override { return base_seq_num_; } | |
32 | |
33 std::vector<StatusSymbol> GetStatusVector() const override { | |
34 return statuses_; | |
35 } | |
36 | |
37 void ParseNextTransportFeedback() { | |
38 statuses_.clear(); | |
39 | |
40 if (!ReadData<uint16_t>(&base_seq_num_)) { | |
41 return; | |
42 } | |
43 | |
44 uint16_t num_statuses = 0; | |
45 if (!ReadData<uint16_t>(&num_statuses)) | |
46 return; | |
47 num_statuses = std::max(num_statuses, static_cast<uint16_t>(1)); | |
kwiberg-webrtc
2017/01/05 02:51:12
I think you can skip the cast if you specify the t
minyue-webrtc
2017/01/19 10:57:55
oh, sounds nice
| |
48 | |
49 while (true) { | |
50 uint8_t status_byte = 0; | |
51 if (!ReadData<uint8_t>(&status_byte)) | |
52 break; | |
kwiberg-webrtc
2017/01/05 02:51:12
Maybe say "return" here, for clarity? Your call.
minyue-webrtc
2017/01/19 10:57:55
that is better.
| |
53 // Each status byte contains 8 statuses. | |
54 for (size_t j = 0; j < 8; ++j) { | |
55 if (status_byte & 0x01) { | |
56 // |kReceivedSmallDelta| and |kReceivedLargeDelta| make no difference | |
57 // to TransportFeedbackPacketLossTracker. So we test only one case. | |
58 statuses_.push_back( | |
59 TransportFeedback::StatusSymbol::kReceivedSmallDelta); | |
60 } else { | |
61 statuses_.push_back(TransportFeedback::StatusSymbol::kNotReceived); | |
62 } | |
63 if (statuses_.size() >= num_statuses) | |
64 return; | |
65 status_byte >>= 1; | |
66 } | |
67 } | |
68 } | |
69 | |
70 bool ended() const { return ended_; } | |
71 | |
72 void SetBase(uint16_t base_sequence, int64_t ref_timestamp_us) override { | |
73 RTC_NOTREACHED(); | |
74 } | |
75 void SetFeedbackSequenceNumber(uint8_t feedback_sequence) override { | |
76 RTC_NOTREACHED(); | |
77 } | |
78 bool AddReceivedPacket(uint16_t sequence_number, | |
79 int64_t timestamp_us) override { | |
80 RTC_NOTREACHED(); | |
81 return false; | |
82 } | |
83 std::vector<int16_t> GetReceiveDeltas() const override { | |
84 RTC_NOTREACHED(); | |
85 return std::vector<int16_t>(); | |
86 } | |
87 int64_t GetBaseTimeUs() const override { | |
88 RTC_NOTREACHED(); | |
89 return 0; | |
90 } | |
91 std::vector<int64_t> GetReceiveDeltasUs() const override { | |
92 RTC_NOTREACHED(); | |
93 return std::vector<int64_t>(); | |
94 } | |
95 | |
96 private: | |
97 template <typename T> | |
98 bool ReadData(T* value) { | |
99 RTC_DCHECK(!ended_); | |
100 if (data_idx_ + sizeof(T) > data_.size()) { | |
101 ended_ = true; | |
102 return false; | |
103 } | |
104 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); | |
105 data_idx_ += sizeof(T); | |
106 return true; | |
107 } | |
108 | |
109 const rtc::ArrayView<const uint8_t> data_; | |
110 bool ended_; | |
111 size_t data_idx_; | |
112 uint16_t base_seq_num_; | |
113 std::vector<TransportFeedback::StatusSymbol> statuses_; | |
114 }; | |
115 | |
116 } // namespace | |
117 | |
118 void FuzzOneInput(const uint8_t* data, size_t size) { | |
119 if (size < sizeof(uint32_t)) { | |
120 return; | |
121 } | |
122 constexpr size_t kSeqNumHalf = 0x8000u; | |
123 const size_t window_size_1 = std::min( | |
124 kSeqNumHalf, | |
125 static_cast<size_t>(std::max(static_cast<uint16_t>(1), | |
kwiberg-webrtc
2017/01/05 02:51:12
Specify template argument explicitly and avoid cas
minyue-webrtc
2017/01/19 10:57:55
Done.
| |
126 ByteReader<uint16_t>::ReadBigEndian(data)))); | |
127 data += sizeof(uint16_t); | |
128 const size_t window_size_2 = std::min( | |
129 kSeqNumHalf, | |
130 static_cast<size_t>(std::max(static_cast<uint16_t>(1), | |
kwiberg-webrtc
2017/01/05 02:51:12
Here too?
minyue-webrtc
2017/01/19 10:57:55
Done.
| |
131 ByteReader<uint16_t>::ReadBigEndian(data)))); | |
132 data += sizeof(uint16_t); | |
133 size -= 2 * sizeof(uint16_t); | |
134 | |
135 TransportFeedbackPacketLossTracker tracker( | |
136 std::min(window_size_1, window_size_2), | |
137 std::max(window_size_1, window_size_2)); | |
138 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size)); | |
139 while (!feedback.ended()) { | |
140 tracker.OnReceivedTransportFeedback(feedback); | |
141 tracker.Validate(); | |
142 feedback.ParseNextTransportFeedback(); | |
143 } | |
144 } | |
145 | |
146 } // namespace webrtc | |
OLD | NEW |