rust-util-collections / vsdb

A KV-database with 'Git-like' features
https://crates.io/crates/vsdb
GNU General Public License v3.0
22 stars 7 forks source link

Unsound collection transmute in `from_bytes` #25

Closed shinmao closed 8 months ago

shinmao commented 1 year ago

Hi, we found that the function from_bytes might cover unsound transmute: https://github.com/rust-util-collections/vsdb/blob/50a45dc4d4b2f563153a514327ec1009957daa13/wrappers/src/common/ende.rs#L405-L417 From my understanding, the deallocator should keep the same layout as it was allocated with; otherwise it could lead to UB. In from_bytes, Vec<u8> is allowed to transmute to Vec<u16>, Vec<u32> Vec<usize>, Vec<u128> and so on. However, we can see that the clippy lint of transmute was suppressed, https://github.com/rust-util-collections/vsdb/blob/50a45dc4d4b2f563153a514327ec1009957daa13/wrappers/src/common/ende.rs#L372 Could you explain more about how you guarantee the transmute between different layout of allocator and deallocator? Thanks!

haxjump commented 1 year ago

they are well aligned types