File: fuzz_decoders.py

package info (click to toggle)
python-multipart 0.0.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 716 kB
  • sloc: python: 2,206; sh: 17; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 919 bytes parent folder | download
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
import io
import sys

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_quoted_decoder(fdp: EnhancedDataProvider) -> None:
    decoder = QuotedPrintableDecoder(io.BytesIO())
    decoder.write(fdp.ConsumeRandomBytes())
    decoder.finalize()


def TestOneInput(data: bytes) -> None:
    fdp = EnhancedDataProvider(data)
    targets = [fuzz_base64_decoder, fuzz_quoted_decoder]
    target = fdp.PickValueInList(targets)

    try:
        target(fdp)
    except DecodeError:
        return


def main():
    atheris.Setup(sys.argv, TestOneInput)
    atheris.Fuzz()


if __name__ == "__main__":
    main()