Coverage for /pythoncovmergedfiles/medio/medio/src/dulwich/fuzzing/fuzz-targets/fuzz_configfile.py: 31%

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

29 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# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 

13 

14import sys 

15from io import BytesIO 

16from typing import Optional 

17 

18import atheris 

19from test_utils import is_expected_exception 

20 

21with atheris.instrument_imports(): 

22 from dulwich.config import ConfigFile 

23 

24 

25def TestOneInput(data) -> Optional[int]: 

26 try: 

27 ConfigFile.from_file(BytesIO(data)) 

28 except ValueError as e: 

29 expected_exceptions = [ 

30 "without section", 

31 "invalid variable name", 

32 "expected trailing ]", 

33 "invalid section name", 

34 "Invalid subsection", 

35 "escape character", 

36 "missing end quote", 

37 ] 

38 if is_expected_exception(expected_exceptions, e): 

39 return -1 

40 else: 

41 raise e 

42 

43 

44def main() -> None: 

45 atheris.Setup(sys.argv, TestOneInput) 

46 atheris.Fuzz() 

47 

48 

49if __name__ == "__main__": 

50 main()