diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc index f95983b4e6..3f06f307a4 100644 --- a/pc/webrtc_sdp.cc +++ b/pc/webrtc_sdp.cc @@ -257,6 +257,9 @@ static const char kDefaultSctpmapProtocol[] = "webrtc-datachannel"; // types. const int kWildcardPayloadType = -1; +// Maximum number of channels allowed. +static const size_t kMaxNumberOfChannels = 24; + struct SsrcInfo { uint32_t ssrc_id; std::string cname; @@ -3628,6 +3631,10 @@ bool ParseRtpmapAttribute(const std::string& line, return false; } } + if (channels > kMaxNumberOfChannels) { + return ParseFailed(line, "At most 24 channels are supported.", error); + } + AudioContentDescription* audio_desc = media_desc->as_audio(); UpdateCodec(payload_type, encoding_name, clock_rate, 0, channels, audio_desc); diff --git a/pc/webrtc_sdp_unittest.cc b/pc/webrtc_sdp_unittest.cc index 883249c20c..21d682315e 100644 --- a/pc/webrtc_sdp_unittest.cc +++ b/pc/webrtc_sdp_unittest.cc @@ -4694,3 +4694,15 @@ TEST_F(WebRtcSdpTest, IllegalMidCharacterValue) { Replace("a=mid:", "a=mid:[]", &sdp); ExpectParseFailure(std::string(sdp), "a=mid:[]"); } + +TEST_F(WebRtcSdpTest, MaxChannels) { + std::string sdp = + "v=0\r\n" + "o=- 11 22 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "m=audio 49232 RTP/AVP 108\r\n" + "a=rtpmap:108 ISAC/16000/512\r\n"; + + ExpectParseFailure(sdp, "a=rtpmap:108 ISAC/16000/512"); +}