mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-08-24 07:06:32 +00:00
fix: validate remote audio channel count (#15673)
This commit is contained in:
@@ -1401,6 +1401,10 @@ impl AudioHandler {
|
||||
|
||||
/// Handle audio format and create an audio decoder.
|
||||
pub fn handle_format(&mut self, f: AudioFormat) {
|
||||
if !is_supported_audio_channel_count(f.channels) {
|
||||
log::error!("Unsupported audio channel count: {}", f.channels);
|
||||
return;
|
||||
}
|
||||
match AudioDecoder::new(f.sample_rate, if f.channels > 1 { Stereo } else { Mono }) {
|
||||
Ok(d) => {
|
||||
let buffer = vec![0.; f.sample_rate as usize * f.channels as usize];
|
||||
@@ -1540,6 +1544,23 @@ impl AudioHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_supported_audio_channel_count(channels: u32) -> bool {
|
||||
(1..=2).contains(&channels)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod audio_format_tests {
|
||||
use super::is_supported_audio_channel_count;
|
||||
|
||||
#[test]
|
||||
fn only_mono_and_stereo_are_supported() {
|
||||
assert!(is_supported_audio_channel_count(1));
|
||||
assert!(is_supported_audio_channel_count(2));
|
||||
assert!(!is_supported_audio_channel_count(0));
|
||||
assert!(!is_supported_audio_channel_count(u32::MAX));
|
||||
}
|
||||
}
|
||||
|
||||
/// Video handler for the [`Client`].
|
||||
pub struct VideoHandler {
|
||||
decoder: Decoder,
|
||||
|
||||
Reference in New Issue
Block a user