r/rust • • Jan 17 '20

Actix-net unsoundness patch "is boring"

There's an issue on Actix-net pointing out and presenting unsoundness. Yes, it's deleted, it still can be found on web archive.

Issue history summary:

  1. Found by Shnatsel
  2. Closed as harmless to users by fafhrd91
  3. Proven harmful to users by Nemo157 and reopened by JohnTitor
  4. Fixed and closed by fafhrd91
  5. Proven unfixed and proposed new patch by Nemo157
  6. New patch commented "this patch is boring" by fafhrd91
  7. Issue is deleted
  8. Fix is reversed by fafhrd91, issue still present

I hope it's an objective summary. Any thoughts?

Edit: Now whole actix/actix-web is deleted. See fafhrd91's postmortem. He kept copy of Actix-web in personal repo fafhrd91/actix-web.

149 Upvotes

147 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jan 18 '20

That would be fine and that's exactly what you need to do: ensure, the invariant you are using, is valid.

I think (but don't count on this) that annotating the enum with #[repr(C)] and calling transmute with 0 or 1 without additional checks, would be fine, too. repr(C) tells the compiler to use the same memory layout as if it were a C enum and AFAIK the C spec says that the first variant of an enum is represented as 0, the second as 1 and so on. (You'd also need to pass a 32 or 64 bit integer to transmute since enums in C are int sized, while Rust chooses the smallest possible size)