Missing wraparound checks in DroplessArena allocation #72624
Labels
C-bug
Category: This is a bug.
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
P-medium
Medium priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
DroplessArena::alloc_raw does not check for wraparound when computing the end of the allocation, pointer arithmetic using
self.ptr
andbytes
:rust/src/libarena/lib.rs
Lines 382 to 391 in aeca4d6
This can be used to make the pointer wrap around, and "allocate", bumping the pointer, without growing the underlying allocation.
Callers
alloc
andalloc_slice
can possibly be argued to be safe due to practical size limits on values and slices, but at leastalloc_from_iter
can be used to trigger this bug and write out of bounds of an allocation.Fixes to make
(Suggested) cleanups to make
<*mut T>::wrapping_add
, and the method should be preferred.alloc_raw
should return something else than&mut [u8]
, because the contents of the slice are uninit. For example a raw slice or a slice ofMaybeUninit
.This came up in discussion in PR #72417
The text was updated successfully, but these errors were encountered: