rust
rust copied to clipboard
Misaligned pointer exposure in `<String as TensorType>::unpack`
The source of unsoundness
Hi, we found an unsound implementation in unpack
which could create a misaligned pointer:
https://github.com/tensorflow/rust/blob/62a3019cfa0720c9744b4bd5f97db953bf4066cf/src/lib.rs#L900-L903
At line 902, the u8
pointer would cast to TF_TString
which had stronger alignment requirements. The misaligned pointer passed to slice::from_raw_parts
would break the safety guarantee. Please check and happy to have a discussion:)
It's not released yet, but as of https://github.com/tensorflow/rust/pull/418 the TensorType trait is sealed. I'd like to follow up by marking that function as unsafe
and hiding it from the docs. It's not intended to be called by client code, and in the code path that uses it internally it simply uses data from the C FFI, which is presumably aligned.