Coverage for /pythoncovmergedfiles/medio/medio/src/jsonpickle/fuzzing/fuzz-targets/fuzz_unpickle.py: 28%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12import sys
13from json import JSONDecodeError
15import atheris
16from utils import is_expected_error
18with atheris.instrument_imports():
19 import jsonpickle
21# Keys are filenames and values are lists of tuples.
22# Each tuple contains a substring of an expected exception message and a line number
23# (or -1 to match any line number).
24expected_errors = {
25 "jsonpickle/unpickler.py": [
26 ("object has no attribute 'split'", 283),
27 ("not enough values to unpack", 283),
28 ("object has no attribute 'split'", 197),
29 ("object has no attribute 'split'", 307),
30 ("object has no attribute 'encode'", 404),
31 ("object has no attribute 'encode'", 407),
32 ("object has no attribute 'encode'", 431),
33 ("object has no attribute 'encode'", 434),
34 ("object is not iterable", 448),
35 ("list indices must be integers or slices", 539),
36 ("object is not iterable", 448),
37 ("object is not iterable", 475),
38 ("object is not iterable", 481),
39 ("object is not iterable", 508),
40 ("object is not iterable", 841),
41 ("object is not iterable", 808),
42 ("object is not iterable", 859),
43 ("object is not iterable", 881),
44 ("object is not iterable", 892),
45 ("unhashable type", 407),
46 ("unhashable type", 841),
47 ("object argument after * must be an iterable", 493),
48 ("object argument after * must be an iterable", 520),
49 ("list index out of range", 160),
50 ("'utf-8' codec can't encode character", 407),
51 ("too many values to unpack", 283),
52 ("too many values to unpack", 511),
53 ("object is not callable", 493),
54 ("object is not callable", 520),
55 ],
56 "base64.py": [
57 ("bad base85 character at", -1),
58 ("base85 overflow in hunk", -1),
59 ("Invalid base64-encoded string", -1),
60 ("Incorrect padding", -1),
61 ],
62}
65def TestOneInput(data):
66 fdp = atheris.FuzzedDataProvider(data)
67 fuzz_string = fdp.ConsumeUnicodeNoSurrogates(
68 fdp.ConsumeIntInRange(0, fdp.remaining_bytes())
69 )
71 try:
72 jsonpickle.unpickler.decode(fuzz_string)
73 except (RecursionError, JSONDecodeError):
74 return -1
75 except Exception as e:
76 if is_expected_error(e, expected_errors):
77 return 0
78 raise e
81def main():
82 atheris.Setup(sys.argv, TestOneInput)
83 atheris.Fuzz()
86if __name__ == "__main__":
87 main()