File: test_ppmd7_fuzzer.py

package info (click to toggle)
python-ppmd 0.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,636 kB
  • sloc: ansic: 2,574; python: 870; cpp: 23; makefile: 21; sh: 2
file content (34 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pathlib
import shutil
import sys
import tempfile

from hypothesis import given
from hypothesis import strategies as st

import ppmd

MAX_SIZE = min(0xFFFFFFFF - 12 * 3, sys.maxsize)


@given(obj=st.binary(min_size=1),
       max_order=st.integers(min_value=2, max_value=64),
       mem_size=st.integers(min_value=1 << 11, max_value=MAX_SIZE))
def test_ppmd7_fuzzer(obj, max_order, mem_size):
    tmp_path = pathlib.Path(tempfile.mkdtemp())
    with tmp_path.joinpath('target.ppmd').open('wb') as target:
        with ppmd.Ppmd7Encoder(target, max_order=max_order, mem_size=mem_size) as enc:
            enc.encode(obj)
            enc.flush()
    with tmp_path.joinpath('target.ppmd').open('rb') as target:
        with ppmd.Ppmd7Decoder(target, max_order=max_order, mem_size=mem_size) as dec:
            res = dec.decode(len(obj))
    assert obj == res
    shutil.rmtree(tmp_path)


if __name__ == "__main__":
    import atheris  # type: ignore  # noqa

    atheris.Setup(sys.argv, test_ppmd7_fuzzer.hypothesis.fuzz_one_input)
    atheris.Fuzz()