filecoin-project / filecoin-ffi

C and CGO bindings for Filecoin's Rust libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enums in FFI types are unsafe

Stebalien opened this issue · comments

It looks like we're using enums in FFI types in several places, but this is inherently unsafe as we can end up creating enums with arbitrary values and the rust type system will assume that this can't happen.

This can cause problems like:

  1. Code checking said enum value may be optimized away.
  2. If the enum has no zero variant but a zero is passed, rust may interpret Option<Enum> as None.
  3. Really, whatever the rust compiler wants to do.

Asfaict all enums that are used are using repr(C) which should make them FFI safe, so I don't think these concerns apply.

Fixed.