Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUB in IoReader::fill_buffer #260
Comments
|
I think we need to handle the read_exact failure exposing uninitialized bytes. I think the best way to do so is to pass a I think without rust-lang/rust#42788 (or whatever end result comes from that), we should just document that we expect |
|
I agree with the suggestion from the previous comment. We would accept a pull request implementing that strategy. |
|
This could probably be unpinned now as the issue is closed. |
|
Well, as stated, the current code may still exhibit UB. I also don't see the current “requirements” (putting this in quotes as safe functions may not make such requirements) documented in a place a user would find. |
|
It might be more trouble than it's worth to library consumers, but I think you could resolve the soundness issue by marking To avoid then needing to litter |
|
Do we have any benchmarks of what it costs to zero the buffer? Since we're reusing the buffer we won't have to zero it on every single invocation of fill_buffer, we only have to zero newly allocated bytes. |
|
Exposing uninitialized bytes and either leaking them to the outside world or using them in place of data is a potential security vulnerability. Please file a security advisory at https://github.com/RustSec/advisory-db so that anyone interested could get notified about this and upgrade to a version with the fix. |
While doing an unsafe-audit of bincode, I found this code in
src/de/read.rs:If read_exact errors, this code might leave temp_buffer longer than the number of initialized bytes. Also, passing uninitialized memory to read_exact is UB. Since
read_exactis a safe fn, any slice that's passed in must be initialized.From @rkruppe on Zulip: