Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: validate remote audio channel count (#15673)

FrederickStempfle5882346caa92
diff --git a/src/client.rs b/src/client.rs
index dcd5941df..5cafeadaf 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -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,