OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "webrtc/base/array_view.h" | 13 #include "webrtc/base/array_view.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | 16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
| 22 template <typename T> |
| 23 T FuzzInput(const uint8_t*& data, size_t& size) { |
| 24 RTC_CHECK(size >= sizeof(T)); |
| 25 T rc = ByteReader<T>::ReadBigEndian(data); |
| 26 data += sizeof(T); |
| 27 size -= sizeof(T); |
| 28 return rc; |
| 29 } |
| 30 |
22 using TransportFeedback = rtcp::TransportFeedback; | 31 using TransportFeedback = rtcp::TransportFeedback; |
23 | 32 |
24 class FuzzTransportFeedback final : public rtcp::TransportFeedbackInterface { | 33 class FuzzTransportFeedback final : public rtcp::TransportFeedbackInterface { |
25 public: | 34 public: |
26 explicit FuzzTransportFeedback(rtc::ArrayView<const uint8_t> data) | 35 explicit FuzzTransportFeedback(rtc::ArrayView<const uint8_t> data) |
27 : data_(data), ended_(false), data_idx_(0) { | 36 : data_(data), ended_(false), data_idx_(0) { |
28 ParseNextTransportFeedback(); | 37 ParseNextTransportFeedback(); |
29 } | 38 } |
30 | 39 |
31 uint16_t GetBaseSequence() const override { return base_seq_num_; } | 40 uint16_t GetBaseSequence() const override { return base_seq_num_; } |
(...skipping 77 matching lines...) Loading... |
109 const rtc::ArrayView<const uint8_t> data_; | 118 const rtc::ArrayView<const uint8_t> data_; |
110 bool ended_; | 119 bool ended_; |
111 size_t data_idx_; | 120 size_t data_idx_; |
112 uint16_t base_seq_num_; | 121 uint16_t base_seq_num_; |
113 std::vector<TransportFeedback::StatusSymbol> statuses_; | 122 std::vector<TransportFeedback::StatusSymbol> statuses_; |
114 }; | 123 }; |
115 | 124 |
116 } // namespace | 125 } // namespace |
117 | 126 |
118 void FuzzOneInput(const uint8_t* data, size_t size) { | 127 void FuzzOneInput(const uint8_t* data, size_t size) { |
119 if (size < sizeof(uint32_t)) { | 128 if (size < 3 * sizeof(uint16_t)) { |
120 return; | 129 return; |
121 } | 130 } |
122 constexpr size_t kSeqNumHalf = 0x8000u; | 131 constexpr size_t kSeqNumHalf = 0x8000u; |
| 132 |
| 133 // Produce min-window, max-window and min_pairs_num_for_rplr, such that: |
| 134 // a. min <= max <= kSeqNumHalf |
| 135 // b. 1 <= min_pairs_num_for_rplr <= max - 1 (fencepost) |
| 136 // Because of /b/, both min and max can't be below 2. |
| 137 |
123 const size_t window_size_1 = std::min( | 138 const size_t window_size_1 = std::min( |
124 kSeqNumHalf, | 139 kSeqNumHalf, |
125 static_cast<size_t>(std::max(static_cast<uint16_t>(1), | 140 static_cast<size_t>(std::max(static_cast<uint16_t>(2), |
126 ByteReader<uint16_t>::ReadBigEndian(data)))); | 141 FuzzInput<uint16_t>(data, size)))); |
127 data += sizeof(uint16_t); | |
128 const size_t window_size_2 = std::min( | 142 const size_t window_size_2 = std::min( |
129 kSeqNumHalf, | 143 kSeqNumHalf, |
| 144 static_cast<size_t>(std::max(static_cast<uint16_t>(2), |
| 145 FuzzInput<uint16_t>(data, size)))); |
| 146 const size_t min_window_size = std::min(window_size_1, window_size_2); |
| 147 const size_t max_window_size = std::max(window_size_1, window_size_2); |
| 148 const size_t min_pairs_num_for_rplr = std::min( |
| 149 max_window_size - 1, |
130 static_cast<size_t>(std::max(static_cast<uint16_t>(1), | 150 static_cast<size_t>(std::max(static_cast<uint16_t>(1), |
131 ByteReader<uint16_t>::ReadBigEndian(data)))); | 151 FuzzInput<uint16_t>(data, size)))); |
132 data += sizeof(uint16_t); | |
133 size -= 2 * sizeof(uint16_t); | |
134 | 152 |
135 TransportFeedbackPacketLossTracker tracker( | 153 TransportFeedbackPacketLossTracker tracker( |
136 std::min(window_size_1, window_size_2), | 154 min_window_size, max_window_size, min_pairs_num_for_rplr); |
137 std::max(window_size_1, window_size_2)); | |
138 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size)); | 155 FuzzTransportFeedback feedback(rtc::ArrayView<const uint8_t>(data, size)); |
139 while (!feedback.ended()) { | 156 while (!feedback.ended()) { |
140 tracker.OnReceivedTransportFeedback(feedback); | 157 tracker.OnReceivedTransportFeedback(feedback); |
141 tracker.Validate(); | 158 tracker.Validate(); |
142 feedback.ParseNextTransportFeedback(); | 159 feedback.ParseNextTransportFeedback(); |
143 } | 160 } |
144 } | 161 } |
145 | 162 |
146 } // namespace webrtc | 163 } // namespace webrtc |
OLD | NEW |