Skip to content

Commit 80e6de8

Browse files
nmoinvazDead2
authored andcommitted
Fixed tab formatting in fuzzers (#414)
* Fixed tab formatting in fuzzers. * Fixed function argument spacing. * Fixed whitespace in comments and strings.
1 parent 503bdef commit 80e6de8

File tree

7 files changed

+454
-458
lines changed

7 files changed

+454
-458
lines changed

test/fuzz/compress_fuzzer.c

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,69 @@ static size_t dataLen;
1919
static void check_compress_level(uint8_t *compr, size_t comprLen,
2020
uint8_t *uncompr, size_t uncomprLen,
2121
int level) {
22-
PREFIX(compress2)(compr, &comprLen, data, dataLen, level);
23-
PREFIX(uncompress)(uncompr, &uncomprLen, compr, comprLen);
22+
PREFIX(compress2)(compr, &comprLen, data, dataLen, level);
23+
PREFIX(uncompress)(uncompr, &uncomprLen, compr, comprLen);
2424

25-
/* Make sure compress + uncompress gives back the input data. */
26-
assert(dataLen == uncomprLen);
27-
assert(0 == memcmp(data, uncompr, dataLen));
25+
/* Make sure compress + uncompress gives back the input data. */
26+
assert(dataLen == uncomprLen);
27+
assert(0 == memcmp(data, uncompr, dataLen));
2828
}
2929

3030
#define put_byte(s, i, c) {s[i] = (unsigned char)(c);}
3131

3232
static void write_zlib_header(uint8_t *s) {
33-
unsigned level_flags = 0; /* compression level (0..3) */
34-
unsigned w_bits = 8; /* window size log2(w_size) (8..16) */
35-
unsigned int header = (Z_DEFLATED + ((w_bits-8)<<4)) << 8;
36-
header |= (level_flags << 6);
33+
unsigned level_flags = 0; /* compression level (0..3) */
34+
unsigned w_bits = 8; /* window size log2(w_size) (8..16) */
35+
unsigned int header = (Z_DEFLATED + ((w_bits-8)<<4)) << 8;
36+
header |= (level_flags << 6);
3737

38-
header += 31 - (header % 31);
38+
header += 31 - (header % 31);
3939

40-
/* s is guaranteed to be longer than 2 bytes. */
41-
put_byte(s, 0, (unsigned char)(header >> 8));
42-
put_byte(s, 1, (unsigned char)(header & 0xff));
40+
/* s is guaranteed to be longer than 2 bytes. */
41+
put_byte(s, 0, (unsigned char)(header >> 8));
42+
put_byte(s, 1, (unsigned char)(header & 0xff));
4343
}
4444

4545
static void check_decompress(uint8_t *compr, size_t comprLen) {
46-
/* We need to write a valid zlib header of size two bytes. Copy the input data
47-
in a larger buffer. Do not modify the input data to avoid libFuzzer error:
48-
fuzz target overwrites its const input. */
49-
size_t copyLen = dataLen + 2;
50-
uint8_t *copy = (uint8_t *)malloc(copyLen);
51-
memcpy(copy + 2, data, dataLen);
52-
write_zlib_header(copy);
53-
54-
PREFIX(uncompress)(compr, &comprLen, copy, copyLen);
55-
free(copy);
46+
/* We need to write a valid zlib header of size two bytes. Copy the input data
47+
in a larger buffer. Do not modify the input data to avoid libFuzzer error:
48+
fuzz target overwrites its const input. */
49+
size_t copyLen = dataLen + 2;
50+
uint8_t *copy = (uint8_t *)malloc(copyLen);
51+
memcpy(copy + 2, data, dataLen);
52+
write_zlib_header(copy);
53+
54+
PREFIX(uncompress)(compr, &comprLen, copy, copyLen);
55+
free(copy);
5656
}
5757

5858
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) {
59-
/* compressBound does not provide enough space for low compression levels. */
60-
size_t comprLen = 100 + 2 * PREFIX(compressBound)(size);
61-
size_t uncomprLen = size;
62-
uint8_t *compr, *uncompr;
59+
/* compressBound does not provide enough space for low compression levels. */
60+
size_t comprLen = 100 + 2 * PREFIX(compressBound)(size);
61+
size_t uncomprLen = size;
62+
uint8_t *compr, *uncompr;
6363

64-
/* Discard inputs larger than 1Mb. */
65-
static size_t kMaxSize = 1024 * 1024;
64+
/* Discard inputs larger than 1Mb. */
65+
static size_t kMaxSize = 1024 * 1024;
6666

67-
if (size < 1 || size > kMaxSize)
68-
return 0;
67+
if (size < 1 || size > kMaxSize)
68+
return 0;
6969

70-
data = d;
71-
dataLen = size;
72-
compr = (uint8_t *)calloc(1, comprLen);
73-
uncompr = (uint8_t *)calloc(1, uncomprLen);
70+
data = d;
71+
dataLen = size;
72+
compr = (uint8_t *)calloc(1, comprLen);
73+
uncompr = (uint8_t *)calloc(1, uncomprLen);
7474

75-
check_compress_level(compr, comprLen, uncompr, uncomprLen, 1);
76-
check_compress_level(compr, comprLen, uncompr, uncomprLen, 3);
77-
check_compress_level(compr, comprLen, uncompr, uncomprLen, 6);
78-
check_compress_level(compr, comprLen, uncompr, uncomprLen, 7);
75+
check_compress_level(compr, comprLen, uncompr, uncomprLen, 1);
76+
check_compress_level(compr, comprLen, uncompr, uncomprLen, 3);
77+
check_compress_level(compr, comprLen, uncompr, uncomprLen, 6);
78+
check_compress_level(compr, comprLen, uncompr, uncomprLen, 7);
7979

80-
check_decompress(compr, comprLen);
80+
check_decompress(compr, comprLen);
8181

82-
free(compr);
83-
free(uncompr);
82+
free(compr);
83+
free(uncompr);
8484

85-
/* This function must return 0. */
86-
return 0;
85+
/* This function must return 0. */
86+
return 0;
8787
}

test/fuzz/example_dict_fuzzer.c

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -96,75 +96,75 @@ void test_dict_deflate(unsigned char **compr, size_t *comprLen)
9696
* Test inflate() with a preset dictionary
9797
*/
9898
void test_dict_inflate(unsigned char *compr, size_t comprLen) {
99-
int err;
100-
PREFIX3(stream) d_stream; /* decompression stream */
101-
unsigned char *uncompr;
102-
103-
d_stream.zalloc = zalloc;
104-
d_stream.zfree = zfree;
105-
d_stream.opaque = (void *)0;
106-
107-
d_stream.next_in = compr;
108-
d_stream.avail_in = (unsigned int)comprLen;
109-
110-
err = PREFIX(inflateInit)(&d_stream);
111-
CHECK_ERR(err, "inflateInit");
112-
113-
uncompr = (uint8_t *)calloc(1, dataLen);
114-
d_stream.next_out = uncompr;
115-
d_stream.avail_out = (unsigned int)dataLen;
116-
117-
for (;;) {
118-
err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
119-
if (err == Z_STREAM_END)
120-
break;
121-
if (err == Z_NEED_DICT) {
122-
if (d_stream.adler != dictId) {
123-
fprintf(stderr, "unexpected dictionary");
124-
exit(1);
125-
}
126-
err = PREFIX(inflateSetDictionary)(
127-
&d_stream, (const unsigned char *)data, dictionaryLen);
99+
int err;
100+
PREFIX3(stream) d_stream; /* decompression stream */
101+
unsigned char *uncompr;
102+
103+
d_stream.zalloc = zalloc;
104+
d_stream.zfree = zfree;
105+
d_stream.opaque = (void *)0;
106+
107+
d_stream.next_in = compr;
108+
d_stream.avail_in = (unsigned int)comprLen;
109+
110+
err = PREFIX(inflateInit)(&d_stream);
111+
CHECK_ERR(err, "inflateInit");
112+
113+
uncompr = (uint8_t *)calloc(1, dataLen);
114+
d_stream.next_out = uncompr;
115+
d_stream.avail_out = (unsigned int)dataLen;
116+
117+
for (;;) {
118+
err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
119+
if (err == Z_STREAM_END)
120+
break;
121+
if (err == Z_NEED_DICT) {
122+
if (d_stream.adler != dictId) {
123+
fprintf(stderr, "unexpected dictionary");
124+
exit(1);
125+
}
126+
err = PREFIX(inflateSetDictionary)(
127+
&d_stream, (const unsigned char *)data, dictionaryLen);
128+
}
129+
CHECK_ERR(err, "inflate with dict");
128130
}
129-
CHECK_ERR(err, "inflate with dict");
130-
}
131131

132-
err = PREFIX(inflateEnd)(&d_stream);
133-
CHECK_ERR(err, "inflateEnd");
132+
err = PREFIX(inflateEnd)(&d_stream);
133+
CHECK_ERR(err, "inflateEnd");
134134

135-
if (memcmp(uncompr, data, dataLen)) {
136-
fprintf(stderr, "bad inflate with dict\n");
137-
exit(1);
138-
}
135+
if (memcmp(uncompr, data, dataLen)) {
136+
fprintf(stderr, "bad inflate with dict\n");
137+
exit(1);
138+
}
139139

140-
free(uncompr);
140+
free(uncompr);
141141
}
142142

143143
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) {
144-
size_t comprLen = 0;
145-
uint8_t *compr;
144+
size_t comprLen = 0;
145+
uint8_t *compr;
146146

147-
/* Discard inputs larger than 100Kb. */
148-
static size_t kMaxSize = 100 * 1024;
147+
/* Discard inputs larger than 100Kb. */
148+
static size_t kMaxSize = 100 * 1024;
149149

150-
if (size < 1 || size > kMaxSize)
151-
return 0;
150+
if (size < 1 || size > kMaxSize)
151+
return 0;
152152

153-
data = d;
154-
dataLen = size;
153+
data = d;
154+
dataLen = size;
155155

156-
/* Set up the contents of the dictionary. The size of the dictionary is
157-
intentionally selected to be of unusual size. To help cover more corner
158-
cases, the size of the dictionary is read from the input data. */
159-
dictionaryLen = data[0];
160-
if (dictionaryLen > dataLen)
161-
dictionaryLen = dataLen;
156+
/* Set up the contents of the dictionary. The size of the dictionary is
157+
intentionally selected to be of unusual size. To help cover more corner
158+
cases, the size of the dictionary is read from the input data. */
159+
dictionaryLen = data[0];
160+
if (dictionaryLen > dataLen)
161+
dictionaryLen = dataLen;
162162

163-
test_dict_deflate(&compr, &comprLen);
164-
test_dict_inflate(compr, comprLen);
163+
test_dict_deflate(&compr, &comprLen);
164+
test_dict_inflate(compr, comprLen);
165165

166-
free(compr);
166+
free(compr);
167167

168-
/* This function must return 0. */
169-
return 0;
168+
/* This function must return 0. */
169+
return 0;
170170
}

0 commit comments

Comments
 (0)