From 58cd385e58428fa1a3db5ccb4bcfc311e5984c38 Mon Sep 17 00:00:00 2001 From: Rasmus Brandt Date: Tue, 26 Jun 2018 13:41:16 +0200 Subject: [PATCH] Fix potential division by zero in VP9 VideoCodecTest. When GetSvcConfig returned fewer spatial layers than the number statically configured from the test, we would crash on a SIGFPE. This is not a problem in the production code, since there we reset the encoder with the correct number of spatial layers whenever the resolution changes. Bug: None Change-Id: I339e4a3c0fa993c7c649533c0eae71e1314194e7 Reviewed-on: https://webrtc-review.googlesource.com/85374 Reviewed-by: Michael Horowitz Reviewed-by: Sergey Silkin Commit-Queue: Rasmus Brandt Cr-Commit-Position: refs/heads/master@{#23741} --- .../video_coding/codecs/test/videocodec_test_fixture_impl.cc | 2 ++ modules/video_coding/codecs/vp9/vp9_impl.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc index abeef3100b..beabdaabfe 100644 --- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc @@ -76,6 +76,8 @@ void ConfigureSvc(VideoCodec* codec_settings) { codec_settings->VP9()->numberOfSpatialLayers, codec_settings->VP9()->numberOfTemporalLayers, /* is_screen_sharing = */ false); + ASSERT_EQ(codec_settings->VP9()->numberOfSpatialLayers, layers.size()) + << "GetSvcConfig returned fewer spatial layers than configured."; for (size_t i = 0; i < layers.size(); ++i) { codec_settings->spatialLayers[i] = layers[i]; diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index 6fffdabb73..f0747e56b8 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -175,6 +175,7 @@ bool VP9EncoderImpl::SetSvcRates( } for (i = 0; i < num_active_spatial_layers_; ++i) { + RTC_CHECK_GT(total, 0); config_->ss_target_bitrate[i] = static_cast( config_->rc_target_bitrate * rate_ratio[i] / total); if (num_temporal_layers_ == 1) { @@ -436,6 +437,7 @@ int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) { if (ExplicitlyConfiguredSpatialLayers()) { for (int i = 0; i < num_spatial_layers_; ++i) { const auto& layer = codec_.spatialLayers[i]; + RTC_CHECK_GT(layer.width, 0); const int scale_factor = codec_.width / layer.width; RTC_DCHECK_GT(scale_factor, 0);