Closed
Description
In this code:
Lines 23 to 32 in 784524f
the transmute casts the &[u8]
to a &OsStr
. There are a couple problems with this:
- This is not actually a safe thing to do, since
&[u8]
can be an arbitrary sequence of bytes, where as&OsStr
cannot on Windows. On Windows, it internally is WTF-8 and it's not clear what, if anything, goes wrong when it isn't WTF-8. (But if it isn't WTF-8, then it could very well break a perfectly valid internal invariant that leads to UB.) A plausible alternative is to makefrom_bytes
unsafe. - The fact that an
&OsStr
is internally a&[u8]
on Windows that is WTF-8 is an implementation detail, and could actually change, leading to an incorrecttransmute
.
Is this code still present in clap 3? If so, could someone explain the motivation for this? I'd be happy to try to help brainstorm ways of removing it.
Metadata
Assignees
Labels
No labels