OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/fuzzing/hpack_fuzz_util.h" | 5 #include "net/spdy/fuzzing/hpack_fuzz_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } else { | 100 } else { |
101 value = context->values[value_index]; | 101 value = context->values[value_index]; |
102 } | 102 } |
103 headers[name] = value; | 103 headers[name] = value; |
104 } | 104 } |
105 return headers; | 105 return headers; |
106 } | 106 } |
107 | 107 |
108 // static | 108 // static |
109 size_t HpackFuzzUtil::SampleExponential(size_t mean, size_t sanity_bound) { | 109 size_t HpackFuzzUtil::SampleExponential(size_t mean, size_t sanity_bound) { |
110 return std::min<size_t>(-std::log(base::RandDouble()) * mean, sanity_bound); | 110 return std::min(static_cast<size_t>(-std::log(base::RandDouble()) * mean), |
| 111 sanity_bound); |
111 } | 112 } |
112 | 113 |
113 // static | 114 // static |
114 bool HpackFuzzUtil::NextHeaderBlock(Input* input, | 115 bool HpackFuzzUtil::NextHeaderBlock(Input* input, |
115 StringPiece* out) { | 116 StringPiece* out) { |
116 // ClusterFuzz may truncate input files if the fuzzer ran out of allocated | 117 // ClusterFuzz may truncate input files if the fuzzer ran out of allocated |
117 // disk space. Be tolerant of these. | 118 // disk space. Be tolerant of these. |
118 CHECK_LE(input->offset, input->input.size()); | 119 CHECK_LE(input->offset, input->input.size()); |
119 if (input->remaining() < sizeof(uint32)) { | 120 if (input->remaining() < sizeof(uint32)) { |
120 return false; | 121 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024); | 181 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024); |
181 | 182 |
182 // Iteratively identify & flip offsets in the buffer bit-sequence. | 183 // Iteratively identify & flip offsets in the buffer bit-sequence. |
183 for (uint64 i = 0; i != bits_to_flip; ++i) { | 184 for (uint64 i = 0; i != bits_to_flip; ++i) { |
184 uint64 bit_offset = base::RandUint64() % buffer_bit_length; | 185 uint64 bit_offset = base::RandUint64() % buffer_bit_length; |
185 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u)); | 186 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u)); |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 } // namespace net | 190 } // namespace net |
OLD | NEW |