(
mutation: Mutation,
rng: &mut R,
dict: DictionaryRef,
input: &mut Vec<u8>,
key: StreamKey,
corpus: &S,
offset: usize,
)
| 177 | } |
| 178 | |
| 179 | pub(crate) fn apply_mutation<R, S>( |
| 180 | mutation: Mutation, |
| 181 | rng: &mut R, |
| 182 | dict: DictionaryRef, |
| 183 | input: &mut Vec<u8>, |
| 184 | key: StreamKey, |
| 185 | corpus: &S, |
| 186 | offset: usize, |
| 187 | ) where |
| 188 | R: Rng, |
| 189 | S: InputSource, |
| 190 | { |
| 191 | let len = input.len(); |
| 192 | match mutation { |
| 193 | Mutation::BitFlip => { |
| 194 | let bit_offset: usize = rng.gen_range(offset * 8..len * 8); |
| 195 | let mask = 1 << (bit_offset % 8); |
| 196 | input[bit_offset / 8] ^= input[bit_offset / 8] & mask; |
| 197 | } |
| 198 | Mutation::IncDec => { |
| 199 | let offset: usize = rng.gen_range(offset..len); |
| 200 | input[offset] = match rng.gen_bool(0.5) { |
| 201 | true => input[offset].wrapping_add(1), |
| 202 | false => input[offset].wrapping_sub(1), |
| 203 | }; |
| 204 | } |
| 205 | |
| 206 | Mutation::ReplaceByte => { |
| 207 | let offset: usize = rng.gen_range(offset..len); |
| 208 | input[offset] = rng.gen(); |
| 209 | } |
| 210 | Mutation::InsertByte => { |
| 211 | let offset: usize = rng.gen_range(offset..len + 1); |
| 212 | input.insert(offset, rng.gen()) |
| 213 | } |
| 214 | Mutation::Insert4 => { |
| 215 | let offset: usize = rng.gen_range(offset..len + 1); |
| 216 | insert_slice(input, &rng.gen::<[u8; 4]>(), offset); |
| 217 | } |
| 218 | |
| 219 | Mutation::InterestingValue => { |
| 220 | let offset: usize = rng.gen_range(offset..len); |
| 221 | let x = INTERESTING_VALUES.choose(rng).unwrap(); |
| 222 | let stride = random_stride(rng, 1 | 2 | 4); |
| 223 | replace_slice_strided(input, x, offset, stride); |
| 224 | } |
| 225 | Mutation::DictReplace => { |
| 226 | let (x, strides) = dict.choose(rng); |
| 227 | let x = if rng.gen() { x } else { random_subslice(rng, x) }; |
| 228 | |
| 229 | let stride = random_stride(rng, strides); |
| 230 | replace_slice_strided(input, x, offset, stride); |
| 231 | } |
| 232 | Mutation::DictInsert => { |
| 233 | let (x, strides) = dict.choose(rng); |
| 234 | let x = if rng.gen() { x } else { random_subslice(rng, x) }; |
| 235 | let stride = random_stride(rng, strides); |
| 236 | insert_slice_strided(input, x, offset, stride); |
no test coverage detected