From 964a88fce1adf9637594d169d7e72823fe344dea Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Fri, 5 Mar 2021 15:17:28 +0100 Subject: [PATCH] Prevent possible out-of-bounds access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It read from simulcast_layers[0] even if vector is empty. Bug: none Change-Id: I293890feda70022beae4247ab10cf8182b4cf4a5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209706 Reviewed-by: Åsa Persson Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/master@{#33391} --- .../video_stream_encoder_resource_manager.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc index 8caeceb97d..1c2e5839f2 100644 --- a/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/video/adaptation/video_stream_encoder_resource_manager.cc @@ -720,16 +720,20 @@ bool VideoStreamEncoderResourceManager::IsSimulcast( const VideoEncoderConfig& encoder_config) { const std::vector& simulcast_layers = encoder_config.simulcast_layers; + if (simulcast_layers.size() <= 1) { + return false; + } + + if (simulcast_layers[0].active) { + // We can't distinguish between simulcast and singlecast when only the + // lowest spatial layer is active. Treat this case as simulcast. + return true; + } - bool is_simulcast = simulcast_layers.size() > 1; - bool is_lowest_layer_active = simulcast_layers[0].active; int num_active_layers = std::count_if(simulcast_layers.begin(), simulcast_layers.end(), [](const VideoStream& layer) { return layer.active; }); - - // We can't distinguish between simulcast and singlecast when only the - // lowest spatial layer is active. Treat this case as simulcast. - return is_simulcast && (num_active_layers > 1 || is_lowest_layer_active); + return num_active_layers > 1; } } // namespace webrtc