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) { | |
stefan-webrtc
2017/02/01 13:11:19
Seems like over complicating things to me that we
sprang_webrtc
2017/02/01 14:27:19
Only used in one place, seems like you don't need
elad.alon_webrtc.org
2017/02/01 15:25:49
Please see the subsequent CL in the series, where
| |
24 RTC_CHECK(*size >= sizeof(T)); | |
sprang_webrtc
2017/02/01 14:27:19
nit: RTC_CHECK_GE
elad.alon_webrtc.org
2017/02/01 15:25:49
Done.
| |
25 T rc = ByteReader<T>::ReadBigEndian(*data); | |
26 *data += sizeof(T); | |
27 *size -= sizeof(T); | |
28 return rc; | |
29 } | |
30 | |
31 size_t FuzzInRange(const uint8_t** data, | |
32 size_t* size, | |
33 size_t lower, | |
34 size_t upper) { | |
35 // Achieve a close-to-uniform distribution. | |
36 RTC_CHECK_LE(lower, upper); | |
37 RTC_CHECK_LT(upper - lower, 1 << (8 * sizeof(uint16_t))); | |
38 const size_t range = upper - lower; | |
39 const uint16_t fuzzed = FuzzInput<uint16_t>(data, size); | |
40 const size_t offset = (static_cast<float>(fuzzed) / 0x10000) * (range + 1); | |
minyue-webrtc
2017/01/31 12:50:19
nit: you probably need an explicit static_cast<siz
elad.alon_webrtc.org
2017/01/31 13:43:54
Do you think I should do that even if all bots pas
minyue-webrtc
2017/01/31 15:09:39
Forget about my saying of std::floor, it returns a
| |
41 RTC_CHECK_LE(offset, range); // (fuzzed <= 0xffff) -> (offset < range + 1) | |
minyue-webrtc
2017/01/31 12:53:27
BTW, this CHECK is not necessary. Aren't you sure
elad.alon_webrtc.org
2017/01/31 13:43:54
This check explains why the calculation above was
minyue-webrtc
2017/01/31 15:09:39
It looks redundant. 40 can speaks for itself.
| |
42 return lower + offset; | |
43 } | |
44 | |
22 class TransportFeedbackGenerator { | 45 class TransportFeedbackGenerator { |
23 public: | 46 public: |
24 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) | 47 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) |
25 : data_(data), ended_(false), data_idx_(0) {} | 48 : data_(data), ended_(false), data_idx_(0) {} |
26 | 49 |
27 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { | 50 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { |
28 uint16_t base_seq_num = 0; | 51 uint16_t base_seq_num = 0; |
29 if (!ReadData<uint16_t>(&base_seq_num)) { | 52 if (!ReadData<uint16_t>(&base_seq_num)) { |
30 return; | 53 return; |
31 } | 54 } |
(...skipping 24 matching lines...) Expand all Loading... | |
56 status_byte >>= 1; | 79 status_byte >>= 1; |
57 } | 80 } |
58 } | 81 } |
59 } | 82 } |
60 | 83 |
61 bool ended() const { return ended_; } | 84 bool ended() const { return ended_; } |
62 | 85 |
63 private: | 86 private: |
64 template <typename T> | 87 template <typename T> |
65 bool ReadData(T* value) { | 88 bool ReadData(T* value) { |
66 RTC_DCHECK(!ended_); | 89 RTC_CHECK(!ended_); |
67 if (data_idx_ + sizeof(T) > data_.size()) { | 90 if (data_idx_ + sizeof(T) > data_.size()) { |
68 ended_ = true; | 91 ended_ = true; |
69 return false; | 92 return false; |
70 } | 93 } |
71 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); | 94 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); |
72 data_idx_ += sizeof(T); | 95 data_idx_ += sizeof(T); |
73 return true; | 96 return true; |
74 } | 97 } |
75 | 98 |
76 const rtc::ArrayView<const uint8_t> data_; | 99 const rtc::ArrayView<const uint8_t> data_; |
77 bool ended_; | 100 bool ended_; |
78 size_t data_idx_; | 101 size_t data_idx_; |
79 }; | 102 }; |
80 | 103 |
81 } // namespace | 104 } // namespace |
82 | 105 |
83 void FuzzOneInput(const uint8_t* data, size_t size) { | 106 void FuzzOneInput(const uint8_t* data, size_t size) { |
84 if (size < sizeof(uint32_t)) { | 107 if (size < 3 * sizeof(uint16_t)) { |
85 return; | 108 return; |
86 } | 109 } |
87 constexpr size_t kSeqNumHalf = 0x8000u; | 110 constexpr size_t kSeqNumHalf = 0x8000u; |
88 const size_t window_size_1 = std::min<size_t>( | 111 |
89 kSeqNumHalf, | 112 // 0x8000 >= max_window_size >= plr_min_num_packets > rplr_min_num_pairs >= 1 |
90 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 113 // (The distribution isn't uniform, but it's enough; more would be overkill.) |
91 data += sizeof(uint16_t); | 114 const size_t max_window_size = FuzzInRange(&data, &size, 2, kSeqNumHalf); |
92 const size_t window_size_2 = std::min<size_t>( | 115 const size_t plr_min_num_packets = |
93 kSeqNumHalf, | 116 FuzzInRange(&data, &size, 2, max_window_size); |
94 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 117 const size_t rplr_min_num_pairs = |
95 data += sizeof(uint16_t); | 118 FuzzInRange(&data, &size, 1, plr_min_num_packets - 1); |
96 size -= 2 * sizeof(uint16_t); | |
97 | 119 |
98 TransportFeedbackPacketLossTracker tracker( | 120 TransportFeedbackPacketLossTracker tracker( |
99 std::min(window_size_1, window_size_2), | 121 max_window_size, plr_min_num_packets, rplr_min_num_pairs); |
100 std::max(window_size_1, window_size_2)); | 122 |
101 TransportFeedbackGenerator feedback_generator( | 123 TransportFeedbackGenerator feedback_generator( |
102 rtc::ArrayView<const uint8_t>(data, size)); | 124 rtc::ArrayView<const uint8_t>(data, size)); |
125 | |
103 while (!feedback_generator.ended()) { | 126 while (!feedback_generator.ended()) { |
104 rtcp::TransportFeedback feedback; | 127 rtcp::TransportFeedback feedback; |
105 feedback_generator.GetNextTransportFeedback(&feedback); | 128 feedback_generator.GetNextTransportFeedback(&feedback); |
106 tracker.OnReceivedTransportFeedback(feedback); | 129 tracker.OnReceivedTransportFeedback(feedback); |
107 tracker.Validate(); | 130 tracker.Validate(); |
108 } | 131 } |
109 } | 132 } |
110 | 133 |
111 } // namespace webrtc | 134 } // namespace webrtc |
OLD | NEW |