From 1aa1d6463a9b59fef3a2a6049624581e748f6e2b Mon Sep 17 00:00:00 2001 From: Per Kjellander Date: Thu, 28 Jan 2021 08:56:43 +0100 Subject: [PATCH] Ensure VideoLayersAllocation.frame_rate_fps can not overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:12000 Change-Id: I14d5f0f987fb20bd74e0428b3791bf370476296e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/204220 Reviewed-by: Erik Språng Commit-Queue: Per Kjellander Cr-Commit-Position: refs/heads/master@{#33089} --- video/video_stream_encoder.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 4215fd9897..c8d6021259 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -260,8 +260,9 @@ VideoLayersAllocation CreateVideoLayersAllocation( // Encoder may drop frames internally if `maxFramerate` is set. spatial_layer.frame_rate_fps = std::min( encoder_config.simulcastStream[si].maxFramerate, - (current_rate.framerate_fps * frame_rate_fraction) / - VideoEncoder::EncoderInfo::kMaxFramerateFraction); + rtc::saturated_cast( + (current_rate.framerate_fps * frame_rate_fraction) / + VideoEncoder::EncoderInfo::kMaxFramerateFraction)); } } else if (encoder_config.numberOfSimulcastStreams == 1) { // TODO(bugs.webrtc.org/12000): Implement support for AV1 with @@ -329,8 +330,9 @@ VideoLayersAllocation CreateVideoLayersAllocation( // Encoder may drop frames internally if `maxFramerate` is set. spatial_layer.frame_rate_fps = std::min( encoder_config.spatialLayers[si].maxFramerate, - (current_rate.framerate_fps * frame_rate_fraction) / - VideoEncoder::EncoderInfo::kMaxFramerateFraction); + rtc::saturated_cast( + (current_rate.framerate_fps * frame_rate_fraction) / + VideoEncoder::EncoderInfo::kMaxFramerateFraction)); } }