##// END OF EJS Templates
fuzz: structured helpers for creating mpatch seed corpus entries...
Augie Fackler -
r38265:06e2fc08 default
parent child Browse files
Show More
@@ -8,11 +8,55 b' ap = argparse.ArgumentParser()'
8 ap.add_argument("out", metavar="some.zip", type=str, nargs=1)
8 ap.add_argument("out", metavar="some.zip", type=str, nargs=1)
9 args = ap.parse_args()
9 args = ap.parse_args()
10
10
11 class deltafrag(object):
12 def __init__(self, start, end, data):
13 self.start = start
14 self.end = end
15 self.data = data
16
17 def __str__(self):
18 return struct.pack(
19 ">lll", self.start, self.end, len(self.data)) + self.data
20
21 class delta(object):
22 def __init__(self, frags):
23 self.frags = frags
24
25 def __str__(self):
26 return ''.join(str(f) for f in self.frags)
27
28 class corpus(object):
29
30 def __init__(self, base, deltas):
31 self.base = base
32 self.deltas = deltas
33
34 def __str__(self):
35 deltas = [str(d) for d in self.deltas]
36 parts = (
37 [
38 struct.pack(">B", len(deltas) + 1),
39 struct.pack(">H", len(self.base)),
40 ]
41 + [struct.pack(">H", len(d)) for d in deltas]
42 + [self.base]
43 + deltas
44 )
45 return "".join(parts)
46
11 with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf:
47 with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf:
12 # Manually constructed entries
48 # Manually constructed entries
13 zf.writestr(
49 zf.writestr(
14 "one_delta_applies",
50 "one_delta_applies",
15 "\x02\x00\x01\x00\ra\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01b",
51 str(corpus('a', [delta([deltafrag(0, 1, 'b')])]))
52 )
53 zf.writestr(
54 "one_delta_starts_late",
55 str(corpus('a', [delta([deltafrag(3, 1, 'b')])]))
56 )
57 zf.writestr(
58 "one_delta_ends_late",
59 str(corpus('a', [delta([deltafrag(0, 20, 'b')])]))
16 )
60 )
17
61
18 # Automatically discovered by running the fuzzer
62 # Automatically discovered by running the fuzzer
General Comments 0
You need to be logged in to leave comments. Login now