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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // static | 114 // static |
115 bool HpackFuzzUtil::NextHeaderBlock(Input* input, | 115 bool HpackFuzzUtil::NextHeaderBlock(Input* input, |
116 StringPiece* out) { | 116 StringPiece* out) { |
117 // 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 |
118 // disk space. Be tolerant of these. | 118 // disk space. Be tolerant of these. |
119 CHECK_LE(input->offset, input->input.size()); | 119 CHECK_LE(input->offset, input->input.size()); |
120 if (input->remaining() < sizeof(uint32)) { | 120 if (input->remaining() < sizeof(uint32)) { |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 size_t length = ntohl(*reinterpret_cast<const uint32*>(input->ptr())); | 124 size_t length = |
| 125 base::NetToHost32(*reinterpret_cast<const uint32*>(input->ptr())); |
125 input->offset += sizeof(uint32); | 126 input->offset += sizeof(uint32); |
126 | 127 |
127 if (input->remaining() < length) { | 128 if (input->remaining() < length) { |
128 return false; | 129 return false; |
129 } | 130 } |
130 *out = StringPiece(input->ptr(), length); | 131 *out = StringPiece(input->ptr(), length); |
131 input->offset += length; | 132 input->offset += length; |
132 return true; | 133 return true; |
133 } | 134 } |
134 | 135 |
135 // static | 136 // static |
136 string HpackFuzzUtil::HeaderBlockPrefix(size_t block_size) { | 137 string HpackFuzzUtil::HeaderBlockPrefix(size_t block_size) { |
137 uint32 length = htonl(block_size); | 138 uint32 length = base::HostToNet32(static_cast<uint32>(block_size)); |
138 return string(reinterpret_cast<char*>(&length), sizeof(uint32)); | 139 return string(reinterpret_cast<char*>(&length), sizeof(uint32)); |
139 } | 140 } |
140 | 141 |
141 // static | 142 // static |
142 void HpackFuzzUtil::InitializeFuzzerContext(FuzzerContext* context) { | 143 void HpackFuzzUtil::InitializeFuzzerContext(FuzzerContext* context) { |
143 context->first_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); | 144 context->first_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); |
144 context->second_stage.reset(new HpackEncoder(ObtainHpackHuffmanTable())); | 145 context->second_stage.reset(new HpackEncoder(ObtainHpackHuffmanTable())); |
145 context->third_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); | 146 context->third_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); |
146 } | 147 } |
147 | 148 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024); | 182 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024); |
182 | 183 |
183 // Iteratively identify & flip offsets in the buffer bit-sequence. | 184 // Iteratively identify & flip offsets in the buffer bit-sequence. |
184 for (uint64 i = 0; i != bits_to_flip; ++i) { | 185 for (uint64 i = 0; i != bits_to_flip; ++i) { |
185 uint64 bit_offset = base::RandUint64() % buffer_bit_length; | 186 uint64 bit_offset = base::RandUint64() % buffer_bit_length; |
186 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u)); | 187 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u)); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 } // namespace net | 191 } // namespace net |
OLD | NEW |