← Back to context

Comment by Ar-Curunir

4 years ago

… it is a solution for every memory-unsafe operation, though?

No. Rust cannot magically avoid memory-unsafe operations when you have to deal with, well, memory. If I throw a byte stream at you and tell you it is formatted like so and so, you have to work with memory and you will create memory bugs.

It can however make it extremely difficult to exploit and it can make such use cases very esoteric (and easier to implement correctly).

  • That's totally untrue, unless you are using a really weird definition of "memory safety". A rust program that doesn't make use of the unsafe keyword will not have memory safety bugs. We've had programming languages for decades that are able to happily process arbitrary bytestreams with incredibly buggy code without ever actually writing to a memory region not reachable through pointers allocated by the ordinary program execution.

    A Java program can't write over the return address on the stack.

    • > A rust program that doesn't make use of the unsafe keyword will not have memory safety bugs

      https://www.cvedetails.com/vulnerability-list/vendor_id-1902...

      What if the bug is in std?

      What if I use a bugged Vec::from_iter?

      What if I use the bugged zip implementation from std?

      You'll probably blame unsafe functions, but those unsafe functions were in std, written by the people who know Rust better than anyone.

      Imagine what you and me could do writing unsafe.

      Imagine trusting a 3rd party library...

      2 replies →