SCTP: Stopped accepting SSRCs higher than max.
Seems to fix asan-related crash.

BUG=https://code.google.com/p/chromium/issues/detail?id=570261

Review URL: https://codereview.webrtc.org/1571853002

Cr-Commit-Position: refs/heads/master@{#11205}
diff --git a/talk/media/sctp/sctpdataengine.cc b/talk/media/sctp/sctpdataengine.cc
index 94f242a..3753cd2 100644
--- a/talk/media/sctp/sctpdataengine.cc
+++ b/talk/media/sctp/sctpdataengine.cc
@@ -729,7 +729,13 @@
   }
 
   const uint32_t ssrc = stream.first_ssrc();
-  if (open_streams_.find(ssrc) != open_streams_.end()) {
+  if (ssrc >= cricket::kMaxSctpSid) {
+    LOG(LS_WARNING) << debug_name_ << "->Add(Send|Recv)Stream(...): "
+                    << "Not adding data stream '" << stream.id
+                    << "' with ssrc=" << ssrc
+                    << " because stream ssrc is too high.";
+    return false;
+  } else if (open_streams_.find(ssrc) != open_streams_.end()) {
     LOG(LS_WARNING) << debug_name_ << "->Add(Send|Recv)Stream(...): "
                     << "Not adding data stream '" << stream.id
                     << "' with ssrc=" << ssrc
diff --git a/talk/media/sctp/sctpdataengine_unittest.cc b/talk/media/sctp/sctpdataengine_unittest.cc
index 4706368..d673c69 100644
--- a/talk/media/sctp/sctpdataengine_unittest.cc
+++ b/talk/media/sctp/sctpdataengine_unittest.cc
@@ -270,12 +270,14 @@
     ProcessMessagesUntilIdle();
   }
 
-  void AddStream(int ssrc) {
+  bool AddStream(int ssrc) {
+    bool ret = true;
     cricket::StreamParams p(cricket::StreamParams::CreateLegacy(ssrc));
-    chan1_->AddSendStream(p);
-    chan1_->AddRecvStream(p);
-    chan2_->AddSendStream(p);
-    chan2_->AddRecvStream(p);
+    ret = ret && chan1_->AddSendStream(p);
+    ret = ret && chan1_->AddRecvStream(p);
+    ret = ret && chan2_->AddSendStream(p);
+    ret = ret && chan2_->AddRecvStream(p);
+    return ret;
   }
 
   cricket::SctpDataMediaChannel* CreateChannel(
@@ -504,6 +506,12 @@
   EXPECT_GT(channel1_ready_to_send_count(), prior_count);
 }
 
+TEST_F(SctpDataMediaChannelTest, RefusesHighNumberedChannels) {
+  SetupConnectedChannels();
+  EXPECT_TRUE(AddStream(1022));
+  EXPECT_FALSE(AddStream(1023));
+}
+
 // Flaky on Linux and Windows. See webrtc:4453.
 #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX)
 #define MAYBE_ReusesAStream DISABLED_ReusesAStream