4 ms·
Would you mind expanding on this a bit? The first thing that comes to mind: struct Foo { foo: Foo, } Is caught by the compiler: error[E00
by shepmaster 10y ago
Would you mind expanding on this a bit? The first thing that comes to mind:
struct Foo {
foo: Foo,
}
Is caught by the compiler:
error[E0072]: recursive type `Foo` has infinite size
--> src/main.rs:1:1
|
1 | struct Foo {
| ^ recursive type has infinite size
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Foo` representable
Obviously, I'm not thinking deep enough to understand the approaches you are mentioning!
- naasking 10y agoI'm not deep into Rust to try myself, but I meant something like type-level integers, perhaps to encode an buffer length, and then a sneaky trait or two that specializes on particular (common) buffer sizes to manipulate the buffer in an exploitable way.
- steveklabnik 10y agoRust doesn't yet have type level integers, so that'll have to be saved for a future contest. (It's highly desired, and there's an RFC open, but it's not clear when they will land.) I like this idea though!
- mbrubeck 10y agoBut there are some crates like https://crates.io/crates/typenum https://crates.io/crates/typenum that implement type-level integers on top of the Rust type system, and quite a few other crates that then use these for things like array operations...
- Gankro 10y agoUsing typenum in production isn't a fireable offence?!
- naasking 10y agoNot natively, but you can do it via phantom type parameters. But that does raise an interesting question: could a malicious crate overload a "safe buffer" operation provided by another crate in this way?