This repository was archived by the owner on Apr 30, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,11 @@ export class Corpus {
1414 private corpusPath : string | undefined ;
1515 private maxInputSize : number ;
1616 private seedLength : number ;
17+ private readonly onlyAscii : boolean ;
1718
18- constructor ( dir : string [ ] ) {
19+ constructor ( dir : string [ ] , onlyAscii : boolean ) {
1920 this . inputs = [ ] ;
21+ this . onlyAscii = onlyAscii ;
2022 this . maxInputSize = 4096 ;
2123 for ( let i of dir ) {
2224 if ( ! fs . existsSync ( i ) ) {
@@ -107,6 +109,16 @@ export class Corpus {
107109 }
108110 }
109111
112+ toAscii ( buf : Buffer ) {
113+ let x ;
114+ for ( let i = 0 ; i < buf . length ; i ++ ) {
115+ x = buf [ i ] & 127 ;
116+ if ( ( x < 0x20 || x > 0x7E ) && x !== 0x09 && ( x < 0xA || x > 0xD ) ) {
117+ buf [ i ] = 0x20 ;
118+ }
119+ }
120+ }
121+
110122 mutate ( buf : Buffer ) {
111123 let res = Buffer . allocUnsafe ( buf . length ) ;
112124 buf . copy ( res , 0 , 0 , buf . length ) ;
@@ -342,6 +354,11 @@ export class Corpus {
342354 if ( res . length > this . maxInputSize ) {
343355 res = res . slice ( 0 , this . maxInputSize )
344356 }
357+
358+ if ( this . onlyAscii ) {
359+ this . toAscii ( res ) ;
360+ }
361+
345362 return res ;
346363 }
347364}
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments