Skip to content

Commit

Permalink
[proto-plus-python] Fix Fuzz Target for Python 3.10
Browse files Browse the repository at this point in the history
In Python 3.10, the fuzz target fails if the `FuzzMsg` class is defined
within `TestOneInput` with the exception:
```
TypeError: Couldn't build proto file into descriptor pool: duplicate
file name __main____default_package.fuzzmsg.proto
```

This was not an issue in Python 3.8. This change is necessary to remain
compatible with the Python version used in the base-builder and
base-runner images.
  • Loading branch information
DaveLak committed Jun 4, 2024
1 parent 60a0368 commit 37d973e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions projects/proto-plus-python/fuzz_json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,29 @@
import proto
from google.protobuf.json_format import ParseError


class FuzzMsg(proto.Message):
val1 = proto.Field(proto.FLOAT, number=1)
val2 = proto.Field(proto.INT32, number=2)
val3 = proto.Field(proto.BOOL, number=3)
val4 = proto.Field(proto.STRING, number=4)


def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)

class FuzzMsg(proto.Message):
val1 = proto.Field(proto.FLOAT, number=1)
val2 = proto.Field(proto.INT32, number=2)
val3 = proto.Field(proto.BOOL, number=3)
val4 = proto.Field(proto.STRING, number=4)

try:
s = FuzzMsg.from_json(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize))
FuzzMsg.to_json(s)
except ParseError:
pass
except TypeError:
pass
except RecursionError:
pass
except (ParseError, TypeError, RecursionError):
return


def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()


if __name__ == "__main__":
main()

0 comments on commit 37d973e

Please sign in to comment.