Closed
Description
As far as I understand, the str types have a pretty strong assumption that they contain valid UTF-8. Any method/function that could break this (such as push_bytes
) is marked as unsafe.
However, it is possible to assign random bytes in the middle of a ~str, breaking the UTF-8 invariant:
rusti: let mut a = ~"test"; a[1] = 0x80;
(a.as_bytes().to_owned(), ::std::str::is_utf8(a.as_bytes()))
(~[116, 128, 115, 116], false)
I think that such assignments should only be allowed in unsafe code.
Update: str.as_mut_buf
should also be unsafe, IMO.
Metadata
Metadata
Assignees
Labels
No labels