Coverage for /pythoncovmergedfiles/medio/medio/src/pdfminer.six/fuzzing/fuzzed_data_provider.py: 77%
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
1import io
3from atheris import FuzzedDataProvider
6class PdfminerFuzzedDataProvider(FuzzedDataProvider): # type: ignore[misc]
7 def ConsumeRandomBytes(self) -> bytes:
8 int_range = self.ConsumeIntInRange(0, self.remaining_bytes())
9 return bytes(self.ConsumeBytes(int_range))
11 def ConsumeRandomString(self) -> str:
12 int_range = self.ConsumeIntInRange(0, self.remaining_bytes())
13 return str(self.ConsumeUnicodeNoSurrogates(int_range))
15 def ConsumeRemainingString(self) -> str:
16 return str(self.ConsumeUnicodeNoSurrogates(self.remaining_bytes()))
18 def ConsumeRemainingBytes(self) -> bytes:
19 return bytes(self.ConsumeBytes(self.remaining_bytes()))
21 def ConsumeMemoryFile(self, all_data: bool = False) -> io.BytesIO:
22 if all_data:
23 return io.BytesIO(self.ConsumeRemainingBytes())
24 else:
25 return io.BytesIO(self.ConsumeRandomBytes())
27 def ConsumeOptionalIntList(
28 self,
29 max_count: int,
30 min: int,
31 max: int,
32 ) -> list[int] | None:
33 if self.ConsumeBool():
34 count = self.ConsumeIntInRange(0, max_count)
35 return [int(i) for i in self.ConsumeIntListInRange(count, min, max)]
36 return None