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
With the changes in 0.40.0, SetFileInformationByHandle now takes &[u8] instead of a pointer and a size. There is no API guarantee that &FILE_BASIC_INFO is punnable to &[u8] without a blessed way of converting between the two and is highly likely to be UB. transmute is definitely not sound here. MaybeUninit is a non-starter because creating a &[u8] reference by casting the pointer into *const u8 and taking a reference is immediate UB.
Friends such as GetFileInformationByHandleEx are also difficult to use in the same way, and may be even worse from the UB side because a mutable reference is required.
The text was updated successfully, but these errors were encountered:
chyyran
changed the title
SetFileInformationByHandle and friends are difficult to use soundly.
SetFileInformationByHandle and friends are difficult to use soundly
Sep 21, 2022
Thanks for reporting! Yes, #2034 is related. #2037 partially fixed this issue by avoiding the array transformation when the metadata wasn't matching the semantics expected of certain types. But in fixing that, I included *c_void types along with *u8 and that hits into APIs like this that end up implying polymorphism. So I've fixed that in an upcoming PR to further exclude APIs with such types from the array transformation.
In 0.39.0, APIs that vary based their input or output based on
FILE_INFO_BY_HANDLE_CLASS
were usable like so with good confidence in their soundness.With the changes in 0.40.0,
SetFileInformationByHandle
now takes&[u8]
instead of a pointer and a size. There is no API guarantee that&FILE_BASIC_INFO
is punnable to&[u8]
without a blessed way of converting between the two and is highly likely to be UB.transmute
is definitely not sound here.MaybeUninit
is a non-starter because creating a&[u8]
reference by casting the pointer into*const u8
and taking a reference is immediate UB.Friends such as
GetFileInformationByHandleEx
are also difficult to use in the same way, and may be even worse from the UB side because a mutable reference is required.The text was updated successfully, but these errors were encountered: