Chromium Code Reviews| 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 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 102 |
| 103 bool Setup(const uint8_t** data, | 103 bool Setup(const uint8_t** data, |
| 104 size_t* size, | 104 size_t* size, |
| 105 std::unique_ptr<TransportFeedbackPacketLossTracker>* tracker) { | 105 std::unique_ptr<TransportFeedbackPacketLossTracker>* tracker) { |
| 106 if (*size < 3 * sizeof(uint16_t)) { | 106 if (*size < 3 * sizeof(uint16_t)) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 | 109 |
| 110 constexpr size_t kSeqNumHalf = 0x8000u; | 110 constexpr size_t kSeqNumHalf = 0x8000u; |
| 111 | 111 |
| 112 // 0x8000 >= max_window_size >= plr_min_num_packets > rplr_min_num_pairs >= 1 | 112 const int64_t max_window_size_ms = FuzzInRange(data, size, 1, 1 << 16); |
| 113 // (The distribution isn't uniform, but it's enough; more would be overkill.) | 113 const size_t plr_min_num_packets = FuzzInRange(data, size, 1, kSeqNumHalf); |
| 114 const size_t max_window_size = FuzzInRange(data, size, 2, kSeqNumHalf); | 114 const size_t rplr_min_num_pairs = FuzzInRange(data, size, 1, kSeqNumHalf - 1); |
| 115 const size_t plr_min_num_packets = | |
| 116 FuzzInRange(data, size, 2, max_window_size); | |
| 117 const size_t rplr_min_num_pairs = | |
| 118 FuzzInRange(data, size, 1, plr_min_num_packets - 1); | |
| 119 | 115 |
| 120 tracker->reset(new TransportFeedbackPacketLossTracker( | 116 tracker->reset(new TransportFeedbackPacketLossTracker( |
| 121 max_window_size, plr_min_num_packets, rplr_min_num_pairs)); | 117 max_window_size_ms, plr_min_num_packets, rplr_min_num_pairs)); |
| 122 | 118 |
| 123 return true; | 119 return true; |
| 124 } | 120 } |
| 125 | 121 |
| 126 bool FuzzSequenceNumberDelta(const uint8_t** data, | 122 bool FuzzSequenceNumberDelta(const uint8_t** data, |
| 127 size_t* size, | 123 size_t* size, |
| 128 uint16_t* delta) { | 124 uint16_t* delta) { |
| 129 // Fuzz with a higher likelihood for immediately consecutive pairs | 125 // Fuzz with a higher likelihood for immediately consecutive pairs |
| 130 // than you would by just fuzzing 1-256. | 126 // than you would by just fuzzing 1-256. |
| 131 // Note: Values higher than 256 still possible, but that would be in a new | 127 // Note: Values higher than 256 still possible, but that would be in a new |
| 132 // packet-sending block. | 128 // packet-sending block. |
| 133 // * Fuzzed value in [0 : 127] (50% chance) -> delta is 1. | 129 // * Fuzzed value in [0 : 127] (50% chance) -> delta is 1. |
| 134 // * Fuzzed value in [128 : 255] (50% chance) -> delta in range [2 : 129]. | 130 // * Fuzzed value in [128 : 255] (50% chance) -> delta in range [2 : 129]. |
| 135 if (*size < sizeof(uint8_t)) { | 131 if (*size < sizeof(uint8_t)) { |
| 136 return false; | 132 return false; |
| 137 } | 133 } |
| 138 uint8_t fuzzed = FuzzInput<uint8_t>(data, size); | 134 uint8_t fuzzed = FuzzInput<uint8_t>(data, size); |
| 139 *delta = (fuzzed < 128) ? 1 : (fuzzed - 128 + 2); | 135 *delta = (fuzzed < 128) ? 1 : (fuzzed - 128 + 2); |
| 140 return true; | 136 return true; |
| 141 } | 137 } |
| 142 | 138 |
| 139 bool FuzzClockAdvancement(const uint8_t** data, | |
| 140 size_t* size, | |
| 141 int64_t* time_ms) { | |
| 142 // Fuzzing 64-bit worth of delta would be extreme overkill, as 32-bit is | |
| 143 // already ~49 days long. We'll fuzz deltas up to a smaller value, and this | |
| 144 // way also guarantee that wrap-around is impossible, as in real life. | |
| 145 | |
| 146 // Higher likelihood for more likely cases: | |
| 147 // 5% chance of delta = 0. | |
| 148 // 20% chance of delta in range [1 : 10] (uniformly distributed) | |
| 149 // 55% chance of delta in range [11 : 500] (uniformly distributed) | |
| 150 // 20% chance of delta in range [501 : 10000] (uniformly distributed) | |
| 151 struct probability_distribution { | |
|
the sun
2017/03/08 20:58:16
ProbabilityDistribution
elad.alon_webrtc.org
2017/03/09 09:51:14
Done.
| |
| 152 float probability; | |
| 153 size_t lower; | |
| 154 size_t higher; | |
| 155 }; | |
| 156 constexpr probability_distribution clock_probability_distribution[] = { | |
| 157 {0.05, 0, 0}, {0.20, 1, 10}, {0.55, 11, 500}, {0.20, 501, 10000}}; | |
| 158 | |
| 159 if (*size < sizeof(uint8_t)) { | |
| 160 return false; | |
| 161 } | |
| 162 const float fuzzed = FuzzInput<uint8_t>(data, size) / 256.0f; | |
| 163 | |
| 164 float cumulative_probability = 0; | |
| 165 for (const auto& dist : clock_probability_distribution) { | |
| 166 cumulative_probability += dist.probability; | |
| 167 if (fuzzed < cumulative_probability) { | |
| 168 if (dist.lower == dist.higher) { | |
| 169 *time_ms += dist.lower; | |
| 170 return true; | |
| 171 } else if (*size < sizeof(uint16_t)) { | |
| 172 return false; | |
| 173 } else { | |
| 174 *time_ms += FuzzInRange(data, size, dist.lower, dist.higher); | |
| 175 return true; | |
| 176 } | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 RTC_NOTREACHED(); | |
| 181 return false; | |
| 182 } | |
| 183 | |
| 143 bool FuzzPacketSendBlock( | 184 bool FuzzPacketSendBlock( |
| 144 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker, | 185 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker, |
| 145 const uint8_t** data, | 186 const uint8_t** data, |
| 146 size_t* size) { | 187 size_t* size, |
| 188 int64_t* time_ms) { | |
| 147 // We want to test with block lengths between 1 and 2^16, inclusive. | 189 // We want to test with block lengths between 1 and 2^16, inclusive. |
| 148 if (*size < sizeof(uint8_t)) { | 190 if (*size < sizeof(uint8_t)) { |
| 149 return false; | 191 return false; |
| 150 } | 192 } |
| 151 size_t packet_block_len = 1 + FuzzInput<uint8_t>(data, size); | 193 size_t packet_block_len = 1 + FuzzInput<uint8_t>(data, size); |
| 152 | 194 |
| 153 // First sent sequence number uniformly selected. | 195 // First sent sequence number uniformly selected. |
| 154 if (*size < sizeof(uint16_t)) { | 196 if (*size < sizeof(uint16_t)) { |
| 155 return false; | 197 return false; |
| 156 } | 198 } |
| 157 uint16_t seq_num = FuzzInput<uint16_t>(data, size); | 199 uint16_t seq_num = FuzzInput<uint16_t>(data, size); |
| 158 tracker->OnPacketAdded(seq_num); | 200 tracker->OnPacketAdded(seq_num, *time_ms); |
| 159 tracker->Validate(); | 201 tracker->Validate(); |
| 160 | 202 |
| 203 bool may_continue = FuzzClockAdvancement(data, size, time_ms); | |
| 204 if (!may_continue) { | |
| 205 return false; | |
| 206 } | |
| 207 | |
| 161 for (size_t i = 1; i < packet_block_len; i++) { | 208 for (size_t i = 1; i < packet_block_len; i++) { |
| 162 uint16_t delta; | 209 uint16_t delta; |
| 163 bool may_continue = FuzzSequenceNumberDelta(data, size, &delta); | 210 may_continue = FuzzSequenceNumberDelta(data, size, &delta); |
| 211 if (!may_continue) | |
| 212 return false; | |
| 213 may_continue = FuzzClockAdvancement(data, size, time_ms); | |
| 164 if (!may_continue) | 214 if (!may_continue) |
| 165 return false; | 215 return false; |
| 166 seq_num += delta; | 216 seq_num += delta; |
| 167 tracker->OnPacketAdded(seq_num); | 217 tracker->OnPacketAdded(seq_num, *time_ms); |
| 168 tracker->Validate(); | 218 tracker->Validate(); |
| 169 } | 219 } |
| 170 | 220 |
| 171 return true; | 221 return true; |
| 172 } | 222 } |
| 173 | 223 |
| 174 bool FuzzTransportFeedbackBlock( | 224 bool FuzzTransportFeedbackBlock( |
| 175 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker, | 225 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker, |
| 176 const uint8_t** data, | 226 const uint8_t** data, |
| 177 size_t* size) { | 227 size_t* size) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 199 } | 249 } |
| 200 | 250 |
| 201 } // namespace | 251 } // namespace |
| 202 | 252 |
| 203 void FuzzOneInput(const uint8_t* data, size_t size) { | 253 void FuzzOneInput(const uint8_t* data, size_t size) { |
| 204 std::unique_ptr<TransportFeedbackPacketLossTracker> tracker; | 254 std::unique_ptr<TransportFeedbackPacketLossTracker> tracker; |
| 205 bool may_continue; | 255 bool may_continue; |
| 206 | 256 |
| 207 may_continue = Setup(&data, &size, &tracker); | 257 may_continue = Setup(&data, &size, &tracker); |
| 208 | 258 |
| 259 // We never expect this to wrap around, so it makes sense to just start with | |
| 260 // a sane value, and keep on incrementing by a fuzzed delta. | |
| 261 if (size < sizeof(uint32_t)) { | |
| 262 return; | |
| 263 } | |
| 264 int64_t time_ms = FuzzInput<uint32_t>(&data, &size); | |
| 265 | |
| 209 while (may_continue) { | 266 while (may_continue) { |
| 210 may_continue = FuzzPacketSendBlock(tracker, &data, &size); | 267 may_continue = FuzzPacketSendBlock(tracker, &data, &size, &time_ms); |
| 211 if (!may_continue) { | 268 if (!may_continue) { |
| 212 return; | 269 return; |
| 213 } | 270 } |
| 214 may_continue = FuzzTransportFeedbackBlock(tracker, &data, &size); | 271 may_continue = FuzzTransportFeedbackBlock(tracker, &data, &size); |
| 215 } | 272 } |
| 216 } | 273 } |
| 217 | 274 |
| 218 } // namespace webrtc | 275 } // namespace webrtc |
| OLD | NEW |