bincode/src
poljar d90f501872 Return an error if a decoded slice length doesn't fit into usize (#491)
* Return an error if a decoded slice length doesn't fit into usize

Bincode encodes a slice length, which is an usize, as an u64. When such
an encoded slice length needs to be decoded it again uses an u64 but
critically it truncates it into an usize.

An usize is architecture dependent, it is the size how many bytes it takes to
reference any location in memory. The most common sizes for an usize are 64, 32,
and 16 bit.

This might lead to silent data loss if the architecture that encoded the
slice differs from the architecture that decoded the slice, i.e. if we
go from a 64 bit architecture to a 32 or 16 bit one.

Since bincode aims to be suitable for storage, aiming to support the
exchange of data between different architectures silently truncating
such slice lenghts should be avoided.

This patch changes the behaviour to error out if we try to decode an
slice lenght that can't fit into the current usize type.

* Remove another two usize truncations

* Rename the error variant if the usize doesn't fit anymore

Co-authored-by: Trangar <victor.koenders@gmail.com>
2022-01-25 17:49:26 +01:00
..
de Return an error if a decoded slice length doesn't fit into usize (#491) 2022-01-25 17:49:26 +01:00
enc Moved Configuration::standard() and ::legacy() to the config module (#481) 2022-01-19 16:46:25 +01:00
features Fix a bunch of typos (#492) 2022-01-25 12:13:38 +01:00
varint Reintroduce varint optimizations 2021-10-24 16:44:36 +02:00
config.rs Moved Configuration::standard() and ::legacy() to the config module (#481) 2022-01-19 16:46:25 +01:00
error.rs Return an error if a decoded slice length doesn't fit into usize (#491) 2022-01-25 17:49:26 +01:00
lib.rs Added a table to the documentation to pick which functions to use (#490) 2022-01-24 16:45:41 +01:00
utils.rs Joined the 2 Sealed traits into a single one 2021-10-21 14:27:03 +02:00