-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathfuzz_decoders.py
More file actions
68 lines (50 loc) · 1.79 KB
/
Copy pathfuzz_decoders.py
File metadata and controls
68 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import io
import logging
import sys
logging.disable(logging.CRITICAL)
import atheris
from helpers import EnhancedDataProvider
with atheris.instrument_imports():
from python_multipart.decoders import Base64Decoder, DecodeError, QuotedPrintableDecoder
def fuzz_base64_decoder(fdp: EnhancedDataProvider) -> None:
decoder = Base64Decoder(io.BytesIO())
decoder.write(fdp.ConsumeRandomBytes())
decoder.finalize()
def fuzz_base64_decoder_chunked(fdp: EnhancedDataProvider) -> None:
decoder = Base64Decoder(io.BytesIO())
num_chunks = fdp.ConsumeIntInRange(1, 8)
body = fdp.ConsumeRandomBytes()
chunk_size = max(1, (len(body) + num_chunks - 1) // num_chunks)
for i in range(0, len(body), chunk_size):
decoder.write(body[i : i + chunk_size])
decoder.finalize()
def fuzz_quoted_decoder(fdp: EnhancedDataProvider) -> None:
decoder = QuotedPrintableDecoder(io.BytesIO())
decoder.write(fdp.ConsumeRandomBytes())
decoder.finalize()
def fuzz_quoted_decoder_chunked(fdp: EnhancedDataProvider) -> None:
decoder = QuotedPrintableDecoder(io.BytesIO())
num_chunks = fdp.ConsumeIntInRange(1, 8)
body = fdp.ConsumeRandomBytes()
chunk_size = max(1, (len(body) + num_chunks - 1) // num_chunks)
for i in range(0, len(body), chunk_size):
decoder.write(body[i : i + chunk_size])
decoder.finalize()
def TestOneInput(data: bytes) -> None:
fdp = EnhancedDataProvider(data)
targets = [
fuzz_base64_decoder,
fuzz_base64_decoder_chunked,
fuzz_quoted_decoder,
fuzz_quoted_decoder_chunked,
]
target = fdp.PickValueInList(targets)
try:
target(fdp)
except DecodeError:
return
def main():
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
if __name__ == "__main__":
main()