uniffi-rs
uniffi-rs copied to clipboard
Change RustBuffer length/capacity to `u64` (#1976)
This fixes #1976, which tracks Rust panics with values that overflow the RustBuffer fields. Note that capacity can overflow even if the rust buffer size is < i32::MAX because of the way vectors grow. As discussed in https://github.com/mozilla/uniffi-rs/pull/1977 one of the simplest ways to fix this is to just make the fields bigger.
In theory, this should be a pretty safe change. I'm a bit worried that I missed some detail though -- especially with Kotlin since JNA always feels like it's full of footguns.
I'd love to know how others feel about this. How risky does it feel to others? Does anyone have performance concerns?
Note: we still write 32-bit lengths to the RustBuffer itself. Should we increase that to 64-bits as well?
This all seems straight-forward, and while I'm surprised there doesn't seem an option for avoid this when we never except the length to exceed 32 bits, I don't see what harm this causes.
I think the one other option would be to implement the vec growth algorithm ourselves by calling reserve_exact() before pushing elements. I prefer this one slightly, but I could go for that option as well.
I think the one other option would be to implement the vec growth algorithm ourselves by calling
reserve_exact()before pushing elements. I prefer this one slightly, but I could go for that option as well.
I don't really have much of an opinion here, but that other option seems like it might come back to bite us - eg, for vecs we don't create.
Talked with Mark about this one and we couldn't see a good reason not to merge this one for 0.27.0.