turborepo
c3fd591e - fix(ffi): fix Rust dangling pointer (#5230)

Commit
2 years ago
fix(ffi): fix Rust dangling pointer (#5230) ### Description Fixes #5202 The underlying issue is how protobuf encodes a message with a single optional field. If that single field is missing the message gets encoded as a zero length string of bytes. This presents a problem with our usage of `Vec::as_mut_ptr` which: ["Returns a dangling raw pointer valid for zero sized reads if the vector didn’t allocate."](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_mut_ptr) This caused us to send a buffer of length 0, but a dangling data pointer instead of a null pointer. This wasn't a consistent failure as Go only checks the validity of all the pointer in the stack under certain conditions. Specifically when growing/shrinking the stack and needing to [adjust pointers in a frame](https://go.googlesource.com/go/+/refs/heads/master/src/runtime/stack.go#626). ### Testing Instructions Added unit tests that deal with zero length buffers: - Rust side ensure that if a protobuf message is zero length we return a buffer with length `0` and the data pointer is the null pointer - Go side the ensures that a buffer with `0` length and a null data pointer gets converted to an empty byte slice --------- Co-authored-by: Chris Olszewski <Chris Olszewski>
Parents
Loading