kytos-ng / python-openflow

Low level OpenFlow messages parser used by Kytos SDN Platform
https://kytos.io/
MIT License
0 stars 3 forks source link

`GenericStruct.unpack` can result in `RuntimeError: dictionary changed` #84

Closed viniarck closed 1 year ago

viniarck commented 1 year ago

This is related to this issue: https://github.com/kytos-ng/of_core/issues/112

The root cause is that GenericStruct.get_class_attributes yields values from a cls.__dict__ which is also being mutated when unpack is being called, which in turn will call _unpack_attribute that is using setattr, this is the mutation that is changing can change the dict size. The dict size depends on internal python implementation, since in the low level implementation it'll allocate upfront this bug isn't deterministic, but it can happen when internally the dict size changes due to a new insertion, which why it took so long to be surfaced and reported. Making a shallow copy should suffice to fix this problem since it's not unpacking recursively when iterating over it.