python-protobuf: extend fuzzer (#7543)

This commit is contained in:
DavidKorczynski 2022-04-09 15:50:17 +01:00 committed by GitHub
parent 0dc7b5ef91
commit 700acdaa21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 12 deletions

View File

@ -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
try:
pbmsg.ParseFromString(input_bytes)
except DecodeError:
None
os.remove(testfile_path)
try:
pbmsg.SerializeToString()
except EncodeError:
None
def main():