| | |
| | |
| | |
| |
|
| | package fuzz |
| |
|
| | |
| | func byteSliceRemoveBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | pos0 := m.rand(len(b)) |
| | pos1 := pos0 + m.chooseLen(len(b)-pos0) |
| | copy(b[pos0:], b[pos1:]) |
| | b = b[:len(b)-(pos1-pos0)] |
| | return b |
| | } |
| |
|
| | |
| | |
| | func byteSliceInsertRandomBytes(m *mutator, b []byte) []byte { |
| | pos := m.rand(len(b) + 1) |
| | n := m.chooseLen(1024) |
| | if len(b)+n >= cap(b) { |
| | return nil |
| | } |
| | b = b[:len(b)+n] |
| | copy(b[pos+n:], b[pos:]) |
| | for i := 0; i < n; i++ { |
| | b[pos+i] = byte(m.rand(256)) |
| | } |
| | return b |
| | } |
| |
|
| | |
| | |
| | func byteSliceDuplicateBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | src := m.rand(len(b)) |
| | dst := m.rand(len(b)) |
| | for dst == src { |
| | dst = m.rand(len(b)) |
| | } |
| | n := m.chooseLen(len(b) - src) |
| | |
| | |
| | |
| | if len(b)+(n*2) >= cap(b) { |
| | return nil |
| | } |
| | end := len(b) |
| | |
| | |
| | b = b[:end+(n*2)] |
| | |
| | |
| | copy(b[end+n:], b[src:src+n]) |
| | |
| | |
| | copy(b[dst+n:end+n], b[dst:end]) |
| | |
| | copy(b[dst:], b[end+n:]) |
| | b = b[:end+n] |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceOverwriteBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | src := m.rand(len(b)) |
| | dst := m.rand(len(b)) |
| | for dst == src { |
| | dst = m.rand(len(b)) |
| | } |
| | n := m.chooseLen(len(b) - src - 1) |
| | copy(b[dst:], b[src:src+n]) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceBitFlip(m *mutator, b []byte) []byte { |
| | if len(b) == 0 { |
| | return nil |
| | } |
| | pos := m.rand(len(b)) |
| | b[pos] ^= 1 << uint(m.rand(8)) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceXORByte(m *mutator, b []byte) []byte { |
| | if len(b) == 0 { |
| | return nil |
| | } |
| | pos := m.rand(len(b)) |
| | |
| | |
| | |
| | b[pos] ^= byte(1 + m.rand(255)) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceSwapByte(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | src := m.rand(len(b)) |
| | dst := m.rand(len(b)) |
| | for dst == src { |
| | dst = m.rand(len(b)) |
| | } |
| | b[src], b[dst] = b[dst], b[src] |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceArithmeticUint8(m *mutator, b []byte) []byte { |
| | if len(b) == 0 { |
| | return nil |
| | } |
| | pos := m.rand(len(b)) |
| | v := byte(m.rand(35) + 1) |
| | if m.r.bool() { |
| | b[pos] += v |
| | } else { |
| | b[pos] -= v |
| | } |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceArithmeticUint16(m *mutator, b []byte) []byte { |
| | if len(b) < 2 { |
| | return nil |
| | } |
| | v := uint16(m.rand(35) + 1) |
| | if m.r.bool() { |
| | v = 0 - v |
| | } |
| | pos := m.rand(len(b) - 1) |
| | enc := m.randByteOrder() |
| | enc.PutUint16(b[pos:], enc.Uint16(b[pos:])+v) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceArithmeticUint32(m *mutator, b []byte) []byte { |
| | if len(b) < 4 { |
| | return nil |
| | } |
| | v := uint32(m.rand(35) + 1) |
| | if m.r.bool() { |
| | v = 0 - v |
| | } |
| | pos := m.rand(len(b) - 3) |
| | enc := m.randByteOrder() |
| | enc.PutUint32(b[pos:], enc.Uint32(b[pos:])+v) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceArithmeticUint64(m *mutator, b []byte) []byte { |
| | if len(b) < 8 { |
| | return nil |
| | } |
| | v := uint64(m.rand(35) + 1) |
| | if m.r.bool() { |
| | v = 0 - v |
| | } |
| | pos := m.rand(len(b) - 7) |
| | enc := m.randByteOrder() |
| | enc.PutUint64(b[pos:], enc.Uint64(b[pos:])+v) |
| | return b |
| | } |
| |
|
| | |
| | |
| | func byteSliceOverwriteInterestingUint8(m *mutator, b []byte) []byte { |
| | if len(b) == 0 { |
| | return nil |
| | } |
| | pos := m.rand(len(b)) |
| | b[pos] = byte(interesting8[m.rand(len(interesting8))]) |
| | return b |
| | } |
| |
|
| | |
| | |
| | func byteSliceOverwriteInterestingUint16(m *mutator, b []byte) []byte { |
| | if len(b) < 2 { |
| | return nil |
| | } |
| | pos := m.rand(len(b) - 1) |
| | v := uint16(interesting16[m.rand(len(interesting16))]) |
| | m.randByteOrder().PutUint16(b[pos:], v) |
| | return b |
| | } |
| |
|
| | |
| | |
| | func byteSliceOverwriteInterestingUint32(m *mutator, b []byte) []byte { |
| | if len(b) < 4 { |
| | return nil |
| | } |
| | pos := m.rand(len(b) - 3) |
| | v := uint32(interesting32[m.rand(len(interesting32))]) |
| | m.randByteOrder().PutUint32(b[pos:], v) |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceInsertConstantBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | dst := m.rand(len(b)) |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | n := m.chooseLen(4096) |
| | if len(b)+n >= cap(b) { |
| | return nil |
| | } |
| | b = b[:len(b)+n] |
| | copy(b[dst+n:], b[dst:]) |
| | rb := byte(m.rand(256)) |
| | for i := dst; i < dst+n; i++ { |
| | b[i] = rb |
| | } |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceOverwriteConstantBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | dst := m.rand(len(b)) |
| | n := m.chooseLen(len(b) - dst) |
| | rb := byte(m.rand(256)) |
| | for i := dst; i < dst+n; i++ { |
| | b[i] = rb |
| | } |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceShuffleBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | dst := m.rand(len(b)) |
| | n := m.chooseLen(len(b) - dst) |
| | if n <= 2 { |
| | return nil |
| | } |
| | |
| | |
| | |
| | for i := n - 1; i > 0; i-- { |
| | j := m.rand(i + 1) |
| | b[dst+i], b[dst+j] = b[dst+j], b[dst+i] |
| | } |
| | return b |
| | } |
| |
|
| | |
| | func byteSliceSwapBytes(m *mutator, b []byte) []byte { |
| | if len(b) <= 1 { |
| | return nil |
| | } |
| | src := m.rand(len(b)) |
| | dst := m.rand(len(b)) |
| | for dst == src { |
| | dst = m.rand(len(b)) |
| | } |
| | |
| | |
| | |
| | max := dst |
| | if src > max { |
| | max = src |
| | } |
| | n := m.chooseLen(len(b) - max - 1) |
| | |
| | |
| | if src > dst && dst+n >= src || dst > src && src+n >= dst { |
| | return nil |
| | } |
| | |
| | |
| | |
| | if len(b)+n >= cap(b) { |
| | return nil |
| | } |
| | end := len(b) |
| | b = b[:end+n] |
| | copy(b[end:], b[dst:dst+n]) |
| | copy(b[dst:], b[src:src+n]) |
| | copy(b[src:], b[end:]) |
| | b = b[:end] |
| | return b |
| | } |
| |
|