Description
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()
method
Lines 432 to 438 in 2f05385
Lines 473 to 475 in 2f05385
metadata::read_application_block()
method
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-provided ReadBytes
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:
It is your responsibility to make sure that
buf
is initialized before callingread
. Calling read with an uninitializedbuf
(of the kind one obtains viaMaybeUninit<T>
) is not safe, and can lead to undefined behavior.
Suggested Fix
It is safe to zero-initialize the newly allocated u8
buffer before read_into()
, in order to prevent user-provided Read
from accessing old contents of the newly allocated heap memory.
Also, there are two nightly features for handling such cases.
- https://doc.rust-lang.org/std/io/struct.Initializer.html
- https://rust-lang.github.io/rfcs/2930-read-buf.html
Thank you for checking out this issue 👍