Memory Safety Is …

15 points by bakaq


mitsuhiko

Memory safety is a property of an implementation.

I think this brings one of my long-standing issues back: Python is not memory safe. You can make it segfault in all kinds of ways, quite easily, by loading embedded bytecode or at runtime via ctypes, or by misusing the buffer interface (There are well-known buffer related use-after-free problem that is essentially inherent to the language because they stem from the C API). That is not something you can realistically fix without breaking Python itself.

And yet people will confidently claim that Python is memory safe, or at least that it should be considered memory safe. In practice, it clearly is not. You can get it to segfault trivially, and you can get it to execute arbitrary native code just as easily. That makes the label hard to defend. But it should probably be considered memory safe, because you have to go out of your way to make it crash. (And it wouldn't be memory safe by Compcert's definition mentioned in the article)

This is why I find "memory safety" very difficult to define cleanly. The term is used in inconsistent and often emotional ways, depending on how people feel about a language rather than where a sensible technical boundary should be drawn. A good example here is also Go: some people argue it is not memory safe because it allows tearing, while others insist it is.

At this point, memory safety has become a hot-button topic with no widely accepted or precise definition, which I find genuinely fascinating.