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-Original-Commit-Position: refs/heads/master@{#19835}
Cr-Mirrored-From: https://webrtc.googlesource.com/src
Cr-Mirrored-Commit: eea063fb955d801f426200a1dbf8608d4981b572
diff --git a/api/audio_codecs/L16/audio_encoder_L16.cc b/api/audio_codecs/L16/audio_encoder_L16.cc
index a0acfe7..99af03d 100644
--- a/api/audio_codecs/L16/audio_encoder_L16.cc
+++ b/api/audio_codecs/L16/audio_encoder_L16.cc
@@ -20,9 +20,12 @@
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>();