Skip to content
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

Should ChannelCount be a sealed trait or marked unsafe? #5

Open
ammaraskar opened this issue Feb 5, 2021 · 0 comments
Open

Should ChannelCount be a sealed trait or marked unsafe? #5

ammaraskar opened this issue Feb 5, 2021 · 0 comments

Comments

@ammaraskar
Copy link

Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that ChannelCount is a public and safe trait. However in these two methods:

pub fn write(&self, data: &[C]) {
let res = unsafe {
let ptr = transmute(data.as_ptr());
pa_simple_write(self.client.simple, ptr, data.len() * C::sample_size(), null_mut())
};
assert!(res == 0);

pub fn read(&self, data: &mut [C]) {
let res = unsafe {
let ptr = transmute(data.as_mut_ptr());
pa_simple_read(self.client.simple, ptr, data.len() * C::sample_size(), null_mut())
};
assert!(res >= 0);
}

If a ChannelCount implementation overrides sample_size and returns a bigger number than expected then this could cause reading out of bounds into data. Or it could cause pulseaudio to write from past the data buffer.

Should ChannelCount or the sample_size method be marked as unsafe and this invariant documented to make sure that this critical property is observed? Alternatively, the ChannelCount trait could be sealed to prevent anyone implementing it externally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant