radicle-dev / radicle-link

The second iteration of the Radicle code collaboration protocol.
Other
421 stars 39 forks source link

net: fix CBOR decoder behaviour on incomplete input #680

Closed kim closed 3 years ago

kim commented 3 years ago

The futures_codec::Decoder impl was adapted from the original serde-based CBOR decoder to minicbor. It turns out that this ported over a bug: when the input buffer does not contain enough data, its offset must not be advanced. Otherwise, the next poll will attempt to decode from that offset instead of the start of the object, which will obviously fail.

Fixes #648

kim commented 3 years ago

I am devastated to realise that the (otherwise really, really good) minicbor crate is by design not capable of incremental decoding due to its insistence on avoiding allocations. This is, however, required for decoding from any kind of IO source (async or not) -- we may frequently receive less bytes than needed to decode the object, but are forced to repeatedly decode from the start.

The CBOR objects we're dealing with are mostly very small, so it shouldn't be an issue usually. I'm tempted to add another patch which wraps the recv streams in a BufRead nevertheless.