Coverage for /pythoncovmergedfiles/medio/medio/src/pdfminer.six/fuzzing/fuzzed_data_provider.py: 78%

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

23 statements  

1import io 

2from typing import List, Optional 

3 

4from atheris import FuzzedDataProvider 

5 

6 

7class PdfminerFuzzedDataProvider(FuzzedDataProvider): # type: ignore[misc] 

8 def ConsumeRandomBytes(self) -> bytes: 

9 int_range = self.ConsumeIntInRange(0, self.remaining_bytes()) 

10 return bytes(self.ConsumeBytes(int_range)) 

11 

12 def ConsumeRandomString(self) -> str: 

13 int_range = self.ConsumeIntInRange(0, self.remaining_bytes()) 

14 return str(self.ConsumeUnicodeNoSurrogates(int_range)) 

15 

16 def ConsumeRemainingString(self) -> str: 

17 return str(self.ConsumeUnicodeNoSurrogates(self.remaining_bytes())) 

18 

19 def ConsumeRemainingBytes(self) -> bytes: 

20 return bytes(self.ConsumeBytes(self.remaining_bytes())) 

21 

22 def ConsumeMemoryFile(self, all_data: bool = False) -> io.BytesIO: 

23 if all_data: 

24 return io.BytesIO(self.ConsumeRemainingBytes()) 

25 else: 

26 return io.BytesIO(self.ConsumeRandomBytes()) 

27 

28 def ConsumeOptionalIntList( 

29 self, 

30 max_count: int, 

31 min: int, 

32 max: int, 

33 ) -> Optional[List[int]]: 

34 if self.ConsumeBool(): 

35 count = self.ConsumeIntInRange(0, max_count) 

36 return [int(i) for i in self.ConsumeIntListInRange(count, min, max)] 

37 return None