fil-c's claims of "total memory safety with no escape hatch" pisses me off becau...
sodiboo :pride_heart: @sodiboo@gaysex.cloud
fil-c's claims of "total memory safety with no escape hatch" pisses me off because like. Yeah. Sure. technically that's true because You Explicitly Don't Support All Use Cases. you do not support ffi with native code, which is one of the primary motivations of having unsafe in literally any language. the other major motivation for "unsafe code" is freestanding/embedded support, which fil-c also explicitly doesn't support, and the third reason is performance in the case that the language's "safe" constructs have too many checks for a particular algorithm that will never fail those checks, which fil-c doesn't address in the slightest (runtime checks always on! always a performance cost! if i wanted unnecessary checks, i wouldn't be using a native language like C or Rust or Zig)
don't get me wrong, "a memory sanitizer runtime with suitable performance to run in production" sounds awesome actually. this definitely can help mitigate against binary exploitation and i'm all for it.
but that's not how it markets itself! it claims to be Actually Memory Safe, by redefining memory safety from how everyone else uses it!
its definition of "memory safety" is something along the lines of "malloc is an intrinsic that returns a slice of memory. every pointer is secretly such a slice, and always bounds-checked and generation checked". but that definition completely ignores the fact that boundaries more granular than a global allocator frame exists. if you have a field in a struct, and pass a pointer to that field, the callee does not know what surrounds it. but fil-c entirely accepts out-of-bounds writes, causing arbitrary memory corruption, as long as they're not going past an intrinsic boundary that it knows. it does not care for what things are even remotely correct to do in a program, as long as it does not violate the contract formed by the global allocator. (it also knows about like, stack variables and such. it's not just malloc. to my understanding, it does offer pretty strong sanitization of variable boundaries being enforced. but put those as fields of one struct, and all safety guarantees are "merged" such that anything valid with either is valid with both)
you can see what i mean by this in a talk the creator gave (timestamped) where he live-demos himself writing past the end of a size-1 buffer (index 3), and it still goddamm works. because the actual top-level allocation is secretly bigger than the data he has a pointer to, he's allowed to misuse that variable without the program panicking.
this is not memory safety. that's an out of bounds read AND write. that's supposed to crash a memory safe program!!!
Rust's restrictions mean things, damnit! &mut [u8] is a statically guaranteed-to-be valid pointer into an address range and whose contents are initialized; similar to a fil-C allocation. if you write out of bounds, your program panics, just like in fil-C. "but there's an escape hatch! boo hoo! you can just cast it to *mut T and then you lose that guarantee" yes, but you don't do that willy-nilly unless you're doing ffi (which is explicitly not supported by fil-c). and if you're not doing ffi, compiling every dependency with the same compiler, you can use miri. look at this playground example. it's unsafe Rust code that goes past the end of a slice, but into perfectly valid memory that hasn't been freed yet. under perfect fil-C semantics, this should be entirely sound and isn't supposed to panic the program. (the example from the talk is a case where fil-C doesn't panic in a case where it should). and if we run it like normal, you can see in the output that it just corrupts the rest of the memory. like you'd expect. but if you click "Tools > Miri" you can run "Entirely Safe Rust Code With No Escape Hatch". it's a sanitizer just like fil-C that makes your raw pointers secretly slices with mandatory bounds checks. but because memory safety is more well defined and &mut references are Strict Semantic Boundaries, it catches the out-of-bounds write that fil-C doesn't even try to catch! the miri-Rust code panics, where *a less well-behaved* fil-C example doesn't panic, and silently corrupts memory instead. the point of Memory Safety is to catch bad behavior, which fil-C is worse at than miri, yet it blatantly claims to be safer!!!
i'm making the comparison to Rust because the author of Fil-C made the same comparison, badly. "you're expected to use unsafe in Rust" is blatantly false! you're expected to avoid it at all costs!!! but even ignoring that, miri provides stronger runtime guarantees than fil-C. i don't know why he thinks the comparison to non-miri Rust is in any way similar.