Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

heap_size_of should be unsafe #9

Closed
bluss opened this issue Aug 9, 2015 · 6 comments
Closed

heap_size_of should be unsafe #9

bluss opened this issue Aug 9, 2015 · 6 comments

Comments

@bluss
Copy link

bluss commented Aug 9, 2015

It draws attention directly by being marked safe but using a raw pointer argument.

It seems trivial to segfault using this function in safe rust, just give it a pointer to something not allocated, or a dangling pointer.

Tested using heapsize 0.1.0

heapsize::heap_size_of(2 as *const _);
@jdm
Copy link
Member

jdm commented Aug 9, 2015

This is true!

@nnethercote
Copy link

Is 2 as *const _ itself not unsafe?

@SimonSapin
Copy link
Member

No, only dereferencing it is.

@bluss
Copy link
Author

bluss commented Aug 10, 2015

let v = vec![0; N]; v[1..].as_ptr() would have the same problem (pointer not from jemalloc). Creating raw pointers being unsafe or not, the precondition is that the passed in pointer must have been returned from jemalloc, and that is not checkable by the type system.

@bluss
Copy link
Author

bluss commented Feb 8, 2016

cool 🍹

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants