You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Emit a warning around thin &CStr interior mutability breaks #118513
Passing an &UnsafeCell<CStr> to size_of_val is currently sound because it just returns the length parameter of the fat pointer. After making CStr thin however, size_of_val will need to call strlen on the data. This is not ok in a &UnsafeCell because another context could be writing the data, e.g. temporarily overwriting the \0.
This seems like something we may be able to emit a warning for?
Incidentally, I wonder if &UnsafeCell<ThinCStr> itself is sound. I wonder if T-opsem should weigh in on that question. A write could happen and change the size of the memory the reference refers to, and the tag won't be correctly sized - maybe it will be shorter than the memory the reference refers to.
Related: my RFC 3536 for !Sized thin pointers had to introduce a new ?Trait to prevent such types from being used with size_of_val(). In general the C concept of DSTs (pointer + computed value size) seems to be incompatible with the Rust semantics of T: ?Sized and size_of_val().
Activity
tgross35 commentedon Dec 1, 2023
Quick search shows this is hopefully not very common https://github.com/search?q=language%3Arust+%2F%26.*UnsafeCell%3CCStr%3E%2F&type=code
chorman0773 commentedon Dec 1, 2023
Incidentally, I wonder if
&UnsafeCell<ThinCStr>itself is sound. I wonder if T-opsem should weigh in on that question. A write could happen and change the size of the memory the reference refers to, and the tag won't be correctly sized - maybe it will be shorter than the memory the reference refers to.&mut ThinCStrmight also have similar issues.jmillikin commentedon Dec 2, 2023
Related: my RFC 3536 for
!Sizedthin pointers had to introduce a new?Traitto prevent such types from being used withsize_of_val(). In general the C concept of DSTs (pointer + computed value size) seems to be incompatible with the Rust semantics ofT: ?Sizedandsize_of_val().