-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading uninitialized memory in Allocator::realloc is unsound #1
Comments
Nice catch! I initially had
A properly behaving realloc implementation is supposed to migrate and initialize the common prefix, who's length is decided here by |
Hm. To my understanding the safety implications of possibly reading uninitialized memory due to a badly implemented would propagate to the underlying application as well, so us doing that for diagnostics purposes would be no better nor worse than having it move into the application. But I suspect we do have a chance of catching it which would be a net positive. I will do the following:
In a future release, I'll put those checks behind an opt-in feature flag instead of having them on by default. @HeroicKatora How does that sound to you? |
That's not strictly true. Contrary to the |
True. Thanks for detailing the issue. I'll reopen until the notices have been amended. I'll make sure they are amended again depending on how rust-lang/unsafe-code-guidelines#71 pans out. Thank you! |
hash_ptr
triggers UB and is generally not sound
I've changed the title since |
First the critical part: In
Allocator::realloc
, the crate fails to check if thedelegate
failed reallocation. This is signalled by a returned null pointer and means that the allocation was not reallocated. It is UB to create a slice from a null pointer in any case.Then also the
hash_ptr
function wraps arbitrary uninitialized memory into a&[u8]
slice. This is unsound and might return inconsistent results which would subvert the usefulness of the hash in the first place.checkers/src/allocator.rs
Line 119 in 99e01e3
checkers/src/allocator.rs
Line 126 in 99e01e3
But it also triggers UB when
fxhash
reads from any uninitialized part of the memory, potentially sooner.Workarounds
Turn off the
realloc
feature.The text was updated successfully, but these errors were encountered: