rust-vmm / vm-memory

Virtual machine's guest memory crate
Apache License 2.0
305 stars 98 forks source link

tests: "We need to get a mut reference to `self.container`." from non-mut &self reference is UB #229

Closed decathorpe closed 1 year ago

decathorpe commented 1 year ago

The code that implements the write_bytes method in the impl Bytes<usize> for MockBytesContainer block here relies on undefined behaviour, in particular, creating a &mut reference to data behind a non-mut reference is bad, since it violates the safety contract of non-mut references.

This code happens to have "worked" until current stable Rust / LLVM 15, but starts to exhibit weird failures with future Rust that will use LLVM 16. If this code really needs to rely on "interior mutability", then self.container should probably wrap the backing data in a RefCell or a Mutex to avoid relying on unsafe / undefined behaviour.

cuviper commented 1 year ago

Should be fixed by #228.

decathorpe commented 1 year ago

Was indeed fixed by #228.