Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit a3f6a9e

Browse files
author
Yevgeny Pats
committed
mutations fine-tuning
1 parent e265dd5 commit a3f6a9e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

examples/fuzzit/fuzz.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
function fuzz(buf) {
3+
const string = buf.toString();
4+
if (string.length === 3) {
5+
if (string[0] === 'f' && string[1] === 'u' && string[2] === 'z') {
6+
throw Error("error")
7+
}
8+
}
9+
}
10+
11+
module.exports = {
12+
fuzz
13+
};

src/corpus.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export class Corpus {
4343

4444
generateInput() {
4545
if (this.inputs.length === 0) {
46-
return this.mutate(Buffer.alloc(1, 0))
46+
const buf = Buffer.alloc(0, 0)
47+
this.putBuffer(buf);
48+
return buf;
4749
}
4850
const buffer = this.inputs[this.rand(this.inputs.length)];
4951
return this.mutate(buffer);
@@ -84,7 +86,8 @@ export class Corpus {
8486
mutate(buf: Buffer) {
8587
let res = Buffer.allocUnsafe(buf.length);
8688
buf.copy(res, 0, 0, buf.length);
87-
const nm = 1 + this.exp2();
89+
// const nm = 1 + this.exp2();
90+
const nm = 1 + this.rand(32);
8891
for (let i=0; i<nm; i++) {
8992
const x = this.rand(16);
9093
if ( x ===0 ) {
@@ -102,7 +105,7 @@ export class Corpus {
102105
// Insert a range of random bytes.
103106
const pos = this.rand(res.length + 1);
104107
const n = this.chooseLen(10);
105-
res = Buffer.concat([res, Buffer.alloc(n, 0)], res.length + n)
108+
res = Buffer.concat([res, Buffer.alloc(n, 0)], res.length + n);
106109
res.copy(res, pos + n, pos);
107110
for (let k = 0; k < n; k++) {
108111
res[pos + k] = this.rand(256)

0 commit comments

Comments
 (0)