diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index e4c1028e78..8a9849d815 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -120,8 +120,7 @@ const char kSimulcastDisabled[] = "WebRTC.PeerConnection.Simulcast.Disabled"; static const int kRtcpCnameLength = 16; // The maximum length of the MID attribute. -// TODO(bugs.webrtc.org/12517) - reduce to 16 again. -static constexpr size_t kMidMaxSize = 32; +static constexpr size_t kMidMaxSize = 16; const char kDefaultStreamId[] = "default"; // NOTE: Duplicated in peer_connection.cc: @@ -408,25 +407,21 @@ bool VerifyIceUfragPwdPresent( RTCError ValidateMids(const cricket::SessionDescription& description) { std::set mids; - size_t max_length = 0; for (const cricket::ContentInfo& content : description.contents()) { if (content.name.empty()) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "A media section is missing a MID attribute."); } - max_length = std::max(max_length, content.name.size()); if (content.name.size() > kMidMaxSize) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "The MID attribute exceeds the maximum supported " - "length of 32 characters."); + "length of 16 characters."); } if (!mids.insert(content.name).second) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Duplicate a=mid value '" + content.name + "'."); } } - RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.PeerConnection.Mid.Size", max_length, 0, - 31, 32); return RTCError::OK(); } diff --git a/pc/sdp_offer_answer_unittest.cc b/pc/sdp_offer_answer_unittest.cc index f21d2b052e..ecac7f8de8 100644 --- a/pc/sdp_offer_answer_unittest.cc +++ b/pc/sdp_offer_answer_unittest.cc @@ -238,4 +238,30 @@ TEST_F(SdpOfferAnswerTest, BundleCodecCollisionInDifferentBundlesAllowed) { "WebRTC.PeerConnection.ValidBundledPayloadTypes", false)); } +TEST_F(SdpOfferAnswerTest, LargeMidsAreRejected) { + auto pc = CreatePeerConnection(); + std::string sdp = + "v=0\r\n" + "o=- 0 3 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "t=0 0\r\n" + "a=fingerprint:sha-1 " + "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" + "a=setup:actpass\r\n" + "a=ice-ufrag:ETEn\r\n" + "a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l\r\n" + "m=video 9 UDP/TLS/RTP/SAVPF 111\r\n" + "c=IN IP4 0.0.0.0\r\n" + "a=rtcp-mux\r\n" + "a=sendonly\r\n" + "a=rtpmap:111 VP8/90000\r\n" + "a=mid:01234567890123456\r\n"; + auto desc = CreateSessionDescription(SdpType::kOffer, sdp); + ASSERT_NE(desc, nullptr); + RTCError error; + pc->SetRemoteDescription(std::move(desc), &error); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::INVALID_PARAMETER); +} + } // namespace webrtc