samcrow / canadensis

A Rust implementation of Cyphal
Apache License 2.0
44 stars 5 forks source link

Fix 16-, 32-, and 64-bit deserialization functions #5

Closed Dx724 closed 3 years ago

Dx724 commented 3 years ago

Currently, the read_u16 function will only read 8 bits, as the second byte read operation will read 16 % 8 (0) bits. The read_u32 and read_u64 functions will attempt to shift by 32 and 64 bits respectively, leading to an error (shift leading to overflow). The functions for reading floats of these sizes (read_f16, read_f32, and read_f64) rely on the respective unsigned read functions, and thus are also affected.

These changes fix the issues mentioned above and also provide tests to verify the functionality being changed.

Thank you for your work in creating this library!

samcrow commented 3 years ago

Thanks for the contribution. I expected that there would be bugs like this, because the serialization and deserialization code is complicated and sparsely tested. Now the number of bugs has decreased.