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

Commit be1d840

Browse files
author
Yevgeny Pats
committed
Merge branch 'master' of github.com:fuzzitdev/jsfuzz
2 parents c05103a + b1f3af8 commit be1d840

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: yevgenypats
4+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ any unnecessary work is done.
148148
* [js-yaml: Crash/TypeError](https://github.com/nodeca/js-yaml/issues/525)
149149
* [asciidoctor: Hang/DoS](https://github.com/asciidoctor/asciidoctor/issues/3472)
150150
* [deanm/omggif: Crash/TypeError](https://github.com/deanm/omggif/issues/41)
151+
* [Leonidas-from-XIV/node-xml2js: Crash/TypeError](https://github.com/Leonidas-from-XIV/node-xml2js/issues/544)
151152

152153
**Feel free to add bugs that you found with jsfuzz to this list via pull-request**

src/corpus.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export class Corpus {
1313
private corpusPath: string | undefined;
1414
private maxInputSize: number;
1515
private seedLength: number;
16+
private readonly onlyAscii: boolean;
1617

17-
constructor(dir: string[]) {
18+
constructor(dir: string[], onlyAscii: boolean) {
1819
this.inputs = [];
20+
this.onlyAscii = onlyAscii;
1921
this.maxInputSize = 4096;
2022
for (let i of dir) {
2123
if (!fs.existsSync(i)) {
@@ -106,6 +108,16 @@ export class Corpus {
106108
}
107109
}
108110

111+
toAscii(buf: Buffer) {
112+
let x;
113+
for (let i = 0; i < buf.length; i++) {
114+
x = buf[i] & 127;
115+
if ((x < 0x20 || x > 0x7E) && x !== 0x09 && (x < 0xA || x > 0xD)) {
116+
buf[i] = 0x20;
117+
}
118+
}
119+
}
120+
109121
mutate(buf: Buffer) {
110122
let res = Buffer.allocUnsafe(buf.length);
111123
buf.copy(res, 0, 0, buf.length);
@@ -341,6 +353,11 @@ export class Corpus {
341353
if (res.length > this.maxInputSize) {
342354
res = res.slice(0, this.maxInputSize)
343355
}
356+
357+
if (this.onlyAscii) {
358+
this.toAscii(res);
359+
}
360+
344361
return res;
345362
}
346363
}

src/fuzzer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ export class Fuzzer {
3333
private regression: boolean;
3434
private verse: Verse | null;
3535
private readonly versifier: boolean;
36+
private readonly onlyAscii: boolean;
3637

3738
constructor(target: string,
3839
dir: string[],
3940
exactArtifactPath: string,
4041
rssLimitMb: number,
4142
timeout: number,
4243
regression: boolean,
44+
onlyAscii: boolean,
4345
versifier: boolean) {
4446
this.target = target;
45-
this.corpus = new Corpus(dir);
47+
this.corpus = new Corpus(dir, onlyAscii);
48+
this.onlyAscii = onlyAscii;
4649
this.versifier = versifier;
4750
this.verse = null;
4851
this.total_executions = 0;

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function startFuzzer(argv: any) {
1010
argv.rssLimitMb,
1111
argv.timeout,
1212
argv.regression,
13+
argv.onlyAscii,
1314
argv.versifier);
1415
fuzzer.start()
1516
}
@@ -56,5 +57,10 @@ require('yargs')
5657
description: 'use versifier algorithm (good for text based protocols)',
5758
default: true,
5859
})
60+
.option('only-ascii', {
61+
type: 'boolean',
62+
description: 'generate only ASCII (isprint+isspace) inputs',
63+
default: false,
64+
})
5965
.help()
6066
.argv;

0 commit comments

Comments
 (0)