Reject configs with ridiculously many channels instead of crashing

We hit this CHECK even though the format wasn't even L16, because we
did the checked_cast before testing the codec name.

BUG=chromium:760994
TBR=ossu@webrtc.org

Change-Id: I382a2f841e51944495500f87650258024030d355
Reviewed-on: https://webrtc-review.googlesource.com/1224
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19835}
This commit is contained in:
Karl Wiberg 2017-09-14 13:49:13 +02:00 committed by Commit Bot
parent 033a1bf337
commit eea063fb95

View File

@ -20,9 +20,12 @@ namespace webrtc {
rtc::Optional<AudioEncoderL16::Config> AudioEncoderL16::SdpToConfig(
const SdpAudioFormat& format) {
if (!rtc::IsValueInRangeForNumericType<int>(format.num_channels)) {
return rtc::Optional<Config>();
}
Config config;
config.sample_rate_hz = format.clockrate_hz;
config.num_channels = rtc::checked_cast<int>(format.num_channels);
config.num_channels = rtc::dchecked_cast<int>(format.num_channels);
return STR_CASE_CMP(format.name.c_str(), "L16") == 0 && config.IsOk()
? rtc::Optional<Config>(config)
: rtc::Optional<Config>();