protofuzz
protofuzz copied to clipboard
Cannot handle message that contains repeated fields
Getting a trace dump from trying to call permute() for a class that contains a repeated field:
Traceback (most recent call last):
File "test_protofuzz.py", line 27, in <module>
gen_message_from_class(Test)
File "test_protofuzz.py", line 22, in gen_message_from_class
for obj in generator.permute():
File "/Users/goyaogo/venvs/test_msg/lib/python3.6/site-packages/protofuzz-0.1-py3.6.egg/protofuzz/protofuzz.py", line 183, in _iteration_helper
yield _fields_to_object(self._descriptor, fields)
File "/Users/goyaogo/venvs/test_msg/lib/python3.6/site-packages/protofuzz-0.1-py3.6.egg/protofuzz/protofuzz.py", line 149, in _fields_to_object
value = _fields_to_object(subtype, value)
File "/Users/goyaogo/venvs/test_msg/lib/python3.6/site-packages/protofuzz-0.1-py3.6.egg/protofuzz/protofuzz.py", line 150, in _fields_to_object
_assign_to_field(obj, name, value)
File "/Users/goyaogo/venvs/test_msg/lib/python3.6/site-packages/protofuzz-0.1-py3.6.egg/protofuzz/protofuzz.py", line 138, in _assign_to_field
raise RuntimeError("Unsupported type: {}".format(type(target)))
RuntimeError: Unsupported type: <class 'google.protobuf.pyext._message.RepeatedScalarContainer'>
After a bit of trial and error I managed to make it run by adding in protofuzz.py:
import google.protobuf.pyext as pyext
and changing some lines further down in the function _assign_to_field(obj, name, val):
if isinstance(target, pyext._message.RepeatedScalarContainer): # containers.RepeatedScalarFieldContainer
target.append(val)
elif isinstance(target, pyext._message.RepeatedScalarContainer): # containers.RepeatedCompositeFieldContainer
target = target.add()
I didn't look into the code too deep and I know this is probably quite hacky, I just focussed on getting it to run. Additionally, the repeated fields will never be filled with more than one value but maybe this will help to at least some extend.