Coverage for /pythoncovmergedfiles/medio/medio/src/fuzzing/projects/pycups/fuzzer/fuzz_UTF8.py: 33%

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

33 statements  

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 

12#!/usr/bin/python3 

13import sys 

14import atheris 

15import cups 

16 

17def TestOneInput(data: bytes): 

18 fdp = atheris.FuzzedDataProvider(data) 

19 

20 try: 

21 # generating fuzzed Unicode string 

22 fuzz_str = fdp.ConsumeUnicodeNoSurrogates(atheris.ALL_REMAINING) 

23 except Exception: 

24 return 

25 

26 try: 

27 conn = cups.Connection() 

28 # string-to-UTF8 conversions 

29 conn.getPPD(fuzz_str) 

30 

31 # UTF8-from-PyObj conversions 

32 utf8_bytes = fuzz_str.encode("utf-8", errors="ignore") 

33 conn.acceptJobs(fuzz_str) 

34 conn.getJobs(which_jobs=fuzz_str) 

35 conn.getJobAttributes(utf8_bytes.decode("utf-8", errors="ignore")) 

36 except Exception: 

37 pass 

38 

39def main(): 

40 atheris.instrument_all() 

41 atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) 

42 atheris.Fuzz() 

43 

44if __name__ == "__main__": 

45 main()