diff options
author | 2022-04-09 15:50:17 +0100 | |
---|---|---|
committer | 2022-04-09 15:50:17 +0100 | |
commit | 700acdaa216f9d2d016fc4f51c8683b6561b57eb (patch) | |
tree | 48345426d4267f61f0322faac7de7fb7f0c8a9d5 /projects/protobuf-python | |
parent | 0dc7b5ef91e62605116dc607a8f0e51258f38a53 (diff) |
python-protobuf: extend fuzzer (#7543)
Diffstat (limited to 'projects/protobuf-python')
-rw-r--r-- | projects/protobuf-python/fuzz_protobuf.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/projects/protobuf-python/fuzz_protobuf.py b/projects/protobuf-python/fuzz_protobuf.py index 02c24ce5..b614df3a 100644 --- a/projects/protobuf-python/fuzz_protobuf.py +++ b/projects/protobuf-python/fuzz_protobuf.py @@ -19,23 +19,21 @@ import atheris with atheris.instrument_imports(): import test_full_pb2 - from google.protobuf.message import DecodeError + from google.protobuf.message import DecodeError, EncodeError @atheris.instrument_func def TestOneInput(input_bytes): - # We need to make the file an absolute path - testfile_path = os.path.join(os.getcwd(), "serialized.bin") - with open(testfile_path, "wb") as f: - f.write(input_bytes) - + """Test ParseFromString with bytes string""" pbmsg = test_full_pb2.TestMessSubMess() - with open(testfile_path, "rb") as fd: - try: - pbmsg.ParseFromString(fd.read()) - except DecodeError: - None - - os.remove(testfile_path) + try: + pbmsg.ParseFromString(input_bytes) + except DecodeError: + None + + try: + pbmsg.SerializeToString() + except EncodeError: + None def main(): |