From f20f788d0b11f1938728d9c784ea030dc6ac0a3c Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Mon, 1 May 2023 15:23:58 +0200 Subject: [PATCH] mac-capture: Fix possible division by zero error Possibility of `mChannelsPerFrame` being 0 is not properly covered by current code, which will result in a division-by-zero error. --- plugins/mac-capture/mac-screen-capture.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/mac-capture/mac-screen-capture.m b/plugins/mac-capture/mac-screen-capture.m index cc09437fa..cc3a5acc8 100644 --- a/plugins/mac-capture/mac-screen-capture.m +++ b/plugins/mac-capture/mac-screen-capture.m @@ -297,6 +297,13 @@ static inline void screen_stream_audio_update(struct screen_capture *sc, CMAudioFormatDescriptionGetStreamBasicDescription( format_description); + if (audio_description->mChannelsPerFrame < 1) { + MACCAP_ERR( + "screen_stream_audio_update: Received sample buffer has less than 1 channel per frame (mChannelsPerFrame set to '%d')\n", + audio_description->mChannelsPerFrame); + return; + } + char *_Nullable bytes = NULL; CMBlockBufferRef data_buffer = CMSampleBufferGetDataBuffer(sample_buffer);