From ca4960380cb3e6439a1c3730b92c9798c00abdee Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 10 Jun 2020 18:27:53 +0200 Subject: [PATCH] Get rid of numpy Numpy's types aren't doing much beside eating CPU and doing a simple wraparound, which can be done via a simple modulo. This commit also unroll a couple of loops. --- pythonfuzz/corpus.py | 60 ++++++++++++++++++++++---------------------- requirements.txt | 2 -- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pythonfuzz/corpus.py b/pythonfuzz/corpus.py index bde80c6..fbbe844 100644 --- a/pythonfuzz/corpus.py +++ b/pythonfuzz/corpus.py @@ -1,6 +1,5 @@ import os import math -import numpy import random import struct import hashlib @@ -9,8 +8,8 @@ INTERESTING8 = [-128, -1, 0, 1, 16, 32, 64, 100, 127] -INTERESTING16 = [-32768, -129, 128, 255, 256, 512, 1000, 1024, 4096, 32767] -INTERESTING32 = [-2147483648, -100663046, -32769, 32768, 65535, 65536, 100663045, 2147483647] +INTERESTING16 = [0, 128, 255, 256, 512, 1000, 1024, 4096, 32767, 65535] +INTERESTING32 = [0, 1, 32768, 65535, 65536, 100663045, 2147483647, 4294967295] # A list of all the mutator clases we have available @@ -206,11 +205,8 @@ def mutate(self, res): if len(res) == 0: return None pos = self._rand(len(res)) - v = self._rand(35) + 1 - if bool(random.getrandbits(1)): - res[pos] = numpy.uint8(res[pos]) + numpy.uint8(v) - else: - res[pos] = numpy.uint8(res[pos]) - numpy.uint8(v) + v = self._rand(2**8) + res[pos] = (res[pos] + v) % 256 return res @@ -223,16 +219,14 @@ def mutate(self, res): if len(res) < 2: return None pos = self._rand(len(res) - 1) - v = numpy.uint16(self._rand(35) + 1) - if bool(random.getrandbits(1)): - v = numpy.uint16(0) - v + v = self._rand(2**16) if bool(random.getrandbits(1)): v = struct.pack('>H', v) else: v = struct.pack('I', v) else: v = struct.pack('Q', v) else: v = struct.pack('H', v) else: v = struct.pack('I', v) else: v = struct.pack('= '3' functools32==3.2.3.post2; python_version < '3'