-
Notifications
You must be signed in to change notification settings - Fork 28
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
Reading on uninitialized memory may cause UB #26
Comments
#19 was opened a few months ago with a proposed a fix for the related parts of code, but it hasn't seen much activity since. |
Thank you for the detailed write-up. I understand that a pathological My first attempt to prevent this was to replace the I think a zero-overhead solution is possible. All call sites that you pointed out have a length known ahead of time. They pass the uninitialized vector to Do you think that 18ae310 would be an adequate solution? |
I wanted to go and benchmark this, but there is a complication: the branch I use in the application is a different one (that adds support for picture metadata), which mostly deletes |
Could a 5% performance hit be worth it in exchange for safety in the short term, until the proper solution that requires refactoring actually lands? The reference FLAC implementation already provides everything but memory safety; I feel memory safety is the main selling point of Claxon, and it's not something that should be compromised on. |
This can be implemented as follows: pub fn read_vec<R>(r: &mut R, onto: &mut Vec<u8>, len: usize) -> Result<usize>
where R: Read
{
onto.reserve(len);
r.take(len as u64).read_to_end(onto)
} This is obviously sound (no |
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
metadata::read_vorbis_comment_block()
methodclaxon/src/metadata.rs
Lines 432 to 438 in 2f05385
claxon/src/metadata.rs
Lines 473 to 475 in 2f05385
metadata::read_application_block()
methodclaxon/src/metadata.rs
Lines 544 to 546 in 2f05385
Methods
metadata::read_vorbis_comment_block()
&metadata::read_application_block()
create an uninitialized buffer and passes it to user-providedReadBytes
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:Suggested Fix
It is safe to zero-initialize the newly allocated
u8
buffer beforeread_into()
, in order to prevent user-providedRead
from accessing old contents of the newly allocated heap memory.Also, there are two nightly features for handling such cases.
Thank you for checking out this issue 👍
The text was updated successfully, but these errors were encountered: