rust-vmm / vm-memory

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

While this might be correct for all usecases, this is not safe for 100% of host target scenarios. Quoting the docs: #237

Closed vireshk closed 8 months ago

vireshk commented 1 year ago
          While this might be correct for all usecases, this is not safe for 100% of host target scenarios. Quoting the docs:

The size of this primitive is how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.

What it is is undefined. That's why there's TryFrom which the compiler should remove if the target's error is infallible.

                usize::try_from(region.len()).expect("usize primitive too small or something like that"),

_Originally posted by @epilys in https://github.com/rust-vmm/vm-memory/pull/235#discussion_r1211417479_

roypat commented 8 months ago

vm-memory explicitly does not support non-64bit targets, so these kind of usize -> u64 and u64 -> usize cases are fine. See also https://github.com/rust-vmm/vm-memory/pull/275