OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 class TransportFeedbackGenerator { | 31 class TransportFeedbackGenerator { |
23 public: | 32 public: |
24 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) | 33 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) |
25 : data_(data), ended_(false), data_idx_(0) {} | 34 : data_(data), ended_(false), data_idx_(0) {} |
26 | 35 |
27 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { | 36 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { |
28 uint16_t base_seq_num = 0; | 37 uint16_t base_seq_num = 0; |
29 if (!ReadData<uint16_t>(&base_seq_num)) { | 38 if (!ReadData<uint16_t>(&base_seq_num)) { |
30 return; | 39 return; |
31 } | 40 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 83 } |
75 | 84 |
76 const rtc::ArrayView<const uint8_t> data_; | 85 const rtc::ArrayView<const uint8_t> data_; |
77 bool ended_; | 86 bool ended_; |
78 size_t data_idx_; | 87 size_t data_idx_; |
79 }; | 88 }; |
80 | 89 |
81 } // namespace | 90 } // namespace |
82 | 91 |
83 void FuzzOneInput(const uint8_t* data, size_t size) { | 92 void FuzzOneInput(const uint8_t* data, size_t size) { |
84 if (size < sizeof(uint32_t)) { | 93 if (size < 3 * sizeof(uint16_t)) { |
85 return; | 94 return; |
86 } | 95 } |
87 constexpr size_t kSeqNumHalf = 0x8000u; | 96 constexpr size_t kSeqNumHalf = 0x8000u; |
| 97 |
| 98 // Produce min-window, max-window and min_pairs_num_for_rplr, such that: |
| 99 // a. min <= max <= kSeqNumHalf |
| 100 // b. 1 <= min_pairs_num_for_rplr <= max - 1 (fencepost) |
| 101 // Because of /b/, both min and max can't be below 2. |
| 102 |
88 const size_t window_size_1 = std::min<size_t>( | 103 const size_t window_size_1 = std::min<size_t>( |
89 kSeqNumHalf, | 104 kSeqNumHalf, |
90 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 105 std::max<uint16_t>(2, FuzzInput<uint16_t>(&data, &size))); |
91 data += sizeof(uint16_t); | |
92 const size_t window_size_2 = std::min<size_t>( | 106 const size_t window_size_2 = std::min<size_t>( |
93 kSeqNumHalf, | 107 kSeqNumHalf, |
94 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 108 std::max<uint16_t>(2, FuzzInput<uint16_t>(&data, &size))); |
95 data += sizeof(uint16_t); | 109 const size_t min_window_size = std::min(window_size_1, window_size_2); |
96 size -= 2 * sizeof(uint16_t); | 110 const size_t max_window_size = std::max(window_size_1, window_size_2); |
| 111 const size_t min_pairs_num_for_rplr = std::min<size_t>( |
| 112 max_window_size - 1, |
| 113 std::max<uint16_t>(1, FuzzInput<uint16_t>(&data, &size))); |
97 | 114 |
98 TransportFeedbackPacketLossTracker tracker( | 115 TransportFeedbackPacketLossTracker tracker( |
99 std::min(window_size_1, window_size_2), | 116 min_window_size, max_window_size, min_pairs_num_for_rplr); |
100 std::max(window_size_1, window_size_2)); | |
101 TransportFeedbackGenerator feedback_generator( | 117 TransportFeedbackGenerator feedback_generator( |
102 rtc::ArrayView<const uint8_t>(data, size)); | 118 rtc::ArrayView<const uint8_t>(data, size)); |
103 while (!feedback_generator.ended()) { | 119 while (!feedback_generator.ended()) { |
104 rtcp::TransportFeedback feedback; | 120 rtcp::TransportFeedback feedback; |
105 feedback_generator.GetNextTransportFeedback(&feedback); | 121 feedback_generator.GetNextTransportFeedback(&feedback); |
106 tracker.OnReceivedTransportFeedback(feedback); | 122 tracker.OnReceivedTransportFeedback(feedback); |
107 tracker.Validate(); | 123 tracker.Validate(); |
108 } | 124 } |
109 } | 125 } |
110 | 126 |
111 } // namespace webrtc | 127 } // namespace webrtc |
OLD | NEW |