MCPcopy Create free account
hub / github.com/boostorg/json / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

fuzzing/fuzz_parser.cpp:88–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86
87extern "C"
88int
89LLVMFuzzerTestOneInput(
90 const uint8_t* data, size_t size)
91{
92 if(size<=5)
93 return 0;
94
95 FuzzHelper fh;
96
97 // set parse options
98 fh.opt.allow_comments=!!(data[0]&0x1);
99 fh.opt.allow_trailing_commas=!!(data[0]&0x2);
100 fh.opt.allow_invalid_utf8=!!(data[0]&0x4);
101 fh.opt.max_depth= (data[0]>>3);
102
103 // select memory strategy to use
104 const int strategy=data[1] & 0x3;
105
106 // select number precision to use
107 const int precision=((data[1] & 0xC) >> 2) % 3;
108 fh.opt.numbers = static_cast<number_precision>(precision);
109
110 // memory limits
111 fh.memlimit1=data[2]*256+data[3];
112 fh.memlimit2=data[4]*256+data[5];
113
114 data+=6;
115 size-=6;
116
117 //set the json string to parse
118 fh.jsontext=string_view{
119 reinterpret_cast<const char*>(
120 data), size};
121 try
122 {
123 switch(strategy) {
124 case 0:
125 fh.useDefault();
126 break;
127 case 1:
128 fh.useMonotonic();
129 break;
130 case 2:
131 fh.useLocalBuffer();
132 break;
133 case 3:
134 fh.useDynLess();
135 break;
136 }
137 }
138 catch(...)
139 {
140 }
141 return 0;
142}
143

Callers

nothing calls this directly

Calls 4

useDefaultMethod · 0.80
useMonotonicMethod · 0.80
useLocalBufferMethod · 0.80
useDynLessMethod · 0.80

Tested by

no test coverage detected