-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
The IsZero
trait is used to specialize vec![val; n]
to use allocate_zeroed
when the val
being duplicated is zero. But in the case of raw pointers, this is not correct as the bytes returned by allocate_zeroed
do not have the same provenance as val
. Thus, the following code triggers undefined behaviour (playground) when it shouldn't
let ptr = std::ptr::from_ref(&42);
let zero = ptr.with_addr(0);
let roundtripped = vec![zero; 1].pop().unwrap();
let new = roundtripped.with_addr(ptr.addr());
unsafe { new.read() };
steffahn, workingjubilee and saethlinscottmcm
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.