concordium-node
concordium-node copied to clipboard
Use a verifier instead of catch_unwind when deserializing network messages.
Task description
Use a flatbuffers verifier instead of relying on catch_unwind.
Previously this was not easily possible since verifiers were not exposed, but version 2.0 of the flatbuffers dependency does expose a verifier, which we should use.
The verifier should check that internal offsets are valid and do not lead to out-of-bounds errors or other problematic behaviour.
According to my investigation, the auto-generated code created by the recent flatc (v2.0.6)
already contains the verification logic. But it seems to be still experimental as described by the following quote from the auto-generated code:
/// Verifies that a buffer of bytes contains a size prefixed
/// `NetworkMessage` and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `size_prefixed_root_as_network_message_unchecked`.
pub fn size_prefixed_root_as_network_message(buf: &[u8]) -> Result<NetworkMessage, flatbuffers::InvalidFlatbuffer> {
So, it seems to be reasonable to keep the catch_unwind
logic for a while more until a stable implementation arrives.
Waiting for flatbuffer implementation including this.