-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read
on uninitialized buffer may cause UB (2 functions)
#400
Comments
Read
on uninitialized bufferRead
on uninitialized buffer may cause UB (2 functions)
For performance reasons we used to read into uninitialized buffers. However this is only safe if you can prove that you won't ever read from the uninitialized memory, which isn't possible in our case since we accept any reader that implements `std::io::Read`. There's no guarantee that the reader only fills our buffer and doesn't also try to read from it. It's unlikely that any reader will actually do that, but there's a slight possibility that we can't prove away. They are currently trying to address this in std, so that you can safely express this. For now we just fall back to zero initializing the buffer. The Llanfair parsing should be rare enough that this shouldn't matter all too much anyway. There are FIXMEs in the code now that someone can eventually fix once the safe reading into unitialized buffers is possible. Resolves LiveSplit#400
Thanks, I was aware of this issue, but wasn't sure if I should wait for the safe solution or fix it. It's pretty unlikely that any Read impl actually reads from the buffer anyway. Anyways, the code isn't all that hot anyway, so it should be fine to zero initialize for now and later switch to the safe abstraction. Thanks for opening this, a PR is now up. |
@CryZe Thank you so much for your quick fix! |
Hello 🦀,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.
Issue Description
livesplit-core/src/run/parser/llanfair.rs
Lines 131 to 145 in d263170
livesplit-core/src/run/parser/llanfair.rs
Lines 243 to 246 in d263170
llanfair::read_string()
&llanfair::parse()
creates an uninitialized buffer and passes it to user-providedRead
implementation. This is unsound, because it allows safe Rust code to exhibit an undefined behavior (read from uninitialized memory).This part from the
Read
trait documentation explains the issue:How to fix the issue?
The Naive & safe way to fix the issue is to always zero-initialize a buffer before lending it to a user-provided
Read
implementation. Note that this approach will add runtime performance overhead of zero-initializing the buffer.As of Jan 2021, there is not yet an ideal fix that works in stable Rust with no performance overhead. Below are links to relevant discussions & suggestions for the fix.
std::io::Initializer
The text was updated successfully, but these errors were encountered: