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

Commit 596dbe6

Browse files
author
Yevgeny Pats
committed
bugfix in mutator algo (now faster)
1 parent 62bd14b commit 596dbe6

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
node_modules
3+
build
4+
crash-*
5+
corpus/*
6+
examples/

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsfuzz",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "Coverage Guided Javascript Fuzzer",
55
"main": "build/src/index.js",
66
"types": "build/src/inde.d.ts",

src/corpus.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,23 @@ export class Corpus {
6868
return Math.floor(Math.random() * Math.floor(n));
6969
}
7070

71-
exp2() {
72-
return Math.round(Math.log2(this.rand(2**32)));
71+
dec2bin(dec: number){
72+
const bin = dec.toString(2);
73+
return '0'.repeat(32 - bin.length) + bin;
74+
}
75+
76+
// Exp2 generates n with probability 1/2^(n+1).
77+
Exp2() {
78+
const bin = this.dec2bin(this.rand(2**32));
79+
let count = 0;
80+
for (let i=0; i<32; i++) {
81+
if(bin[i] === '0') {
82+
count += 1;
83+
} else {
84+
break;
85+
}
86+
}
87+
return count;
7388
}
7489

7590
chooseLen(n: number) {
@@ -86,8 +101,7 @@ export class Corpus {
86101
mutate(buf: Buffer) {
87102
let res = Buffer.allocUnsafe(buf.length);
88103
buf.copy(res, 0, 0, buf.length);
89-
// const nm = 1 + this.exp2();
90-
const nm = 1 + this.rand(32);
104+
const nm = 1 + this.Exp2();
91105
for (let i=0; i<nm; i++) {
92106
const x = this.rand(16);
93107
if ( x ===0 ) {

0 commit comments

Comments
 (0)