treebitmap icon indicating copy to clipboard operation
treebitmap copied to clipboard

Illegal use of mem::zeroed()

Open RalfJung opened this issue 5 years ago • 2 comments

The use of mem::zeroed at https://github.com/hroi/treebitmap/blob/9540ae5e84d3f5123306588af45d0bd71f22cc44/src/tree_bitmap/allocator.rs#L195 looks illegal: mem::zeroed may only be used for types that actually allow zero-initialization, and here this is done for any user-controlled type T. So, e.g. if T is a reference, this is UB as references must not be all-zero.

If you just want to write a bunch of zero bytes to memory, I suggest using write_bytes.

RalfJung avatar Dec 23 '19 12:12 RalfJung

Heads-up: with https://github.com/rust-lang/rust/pull/66059, this will turn into a panic to protect people from UB. The crater log indicates that the type you are zero-initializing here is &str -- references must indeed never be null.

Cc @JakubOnderka, maintainer of ip_network_table, which according to crater will also be affected when the UB here turns into a panic.

RalfJung avatar Feb 16 '20 21:02 RalfJung

This issue is resolved right? It's still open

cc @JakubOnderka , @hroi

nico-abram avatar Nov 22 '20 05:11 nico-abram