Bug 1435025: don't parse padding on SRTP packets r=bwc,jesup
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Wed, 07 Feb 2018 22:50:55 -0800
changeset 458204 a9cf23c66a7e88b6f455753829d9e90e0fb3e5bc
parent 458203 75364898f5f63633d8c42a6aff66a185c36cc084
child 458205 9c7207731ee192a8d76b4c5662adb585fec45698
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc, jesup
bugs1435025
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435025: don't parse padding on SRTP packets r=bwc,jesup MozReview-Commit-ID: HNW2BTRoJp2
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/trunk/webrtc/modules/rtp_rtcp/include/rtp_header_parser.h
media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1101,17 +1101,17 @@ MediaPipeline::RtpPacketReceived(Transpo
   }
 
   // Filter out everything but RTP/RTCP
   if (aData[0] < 128 || aData[0] > 191) {
     return;
   }
 
   webrtc::RTPHeader header;
-  if (!mRtpParser->Parse(aData, aLen, &header)) {
+  if (!mRtpParser->Parse(aData, aLen, &header, true)) {
     return;
   }
 
   if (mFilter && !mFilter->Filter(header)) {
     return;
   }
 
   // Make sure to only get the time once, and only if we need it by
--- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/include/rtp_header_parser.h
+++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/include/rtp_header_parser.h
@@ -26,17 +26,18 @@ class RtpHeaderParser {
   static bool IsRtcp(const uint8_t* packet, size_t length);
 
   // Parses the packet and stores the parsed packet in |header|. Returns true on
   // success, false otherwise.
   // This method is thread-safe in the sense that it can parse multiple packets
   // at once.
   virtual bool Parse(const uint8_t* packet,
                      size_t length,
-                     RTPHeader* header) const = 0;
+                     RTPHeader* header,
+                     bool secured = false) const = 0;
 
   // Registers an RTP header extension and binds it to |id|.
   virtual bool RegisterRtpHeaderExtension(RTPExtensionType type,
                                           uint8_t id) = 0;
 
   // De-registers an RTP header extension.
   virtual bool DeregisterRtpHeaderExtension(RTPExtensionType type) = 0;
 };
--- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
+++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_header_parser.cc
@@ -17,17 +17,18 @@ namespace webrtc {
 
 class RtpHeaderParserImpl : public RtpHeaderParser {
  public:
   RtpHeaderParserImpl();
   virtual ~RtpHeaderParserImpl() {}
 
   bool Parse(const uint8_t* packet,
              size_t length,
-             RTPHeader* header) const override;
+             RTPHeader* header,
+             bool secured) const override;
 
   bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id) override;
 
   bool DeregisterRtpHeaderExtension(RTPExtensionType type) override;
 
  private:
   rtc::CriticalSection critical_section_;
   RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(critical_section_);
@@ -41,27 +42,28 @@ RtpHeaderParserImpl::RtpHeaderParserImpl
 
 bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) {
   RtpUtility::RtpHeaderParser rtp_parser(packet, length);
   return rtp_parser.RTCP();
 }
 
 bool RtpHeaderParserImpl::Parse(const uint8_t* packet,
                                 size_t length,
-                                RTPHeader* header) const {
+                                RTPHeader* header,
+                                bool secured) const {
   RtpUtility::RtpHeaderParser rtp_parser(packet, length);
   memset(header, 0, sizeof(*header));
 
   RtpHeaderExtensionMap map;
   {
     rtc::CritScope cs(&critical_section_);
     map = rtp_header_extension_map_;
   }
 
-  const bool valid_rtpheader = rtp_parser.Parse(header, &map);
+  const bool valid_rtpheader = rtp_parser.Parse(header, &map, secured);
   if (!valid_rtpheader) {
     return false;
   }
   return true;
 }
 
 bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type,
                                                      uint8_t id) {
--- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
+++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
@@ -175,17 +175,18 @@ bool RtpHeaderParser::ParseRtcp(RTPHeade
   if (header->headerLength > static_cast<size_t>(length)) {
     return false;
   }
 
   return true;
 }
 
 bool RtpHeaderParser::Parse(RTPHeader* header,
-                            RtpHeaderExtensionMap* ptrExtensionMap) const {
+                            RtpHeaderExtensionMap* ptrExtensionMap,
+                            bool secured) const {
   const ptrdiff_t length = _ptrRTPDataEnd - _ptrRTPDataBegin;
   if (length < kRtpMinParseLength) {
     return false;
   }
 
   // Version
   const uint8_t V  = _ptrRTPDataBegin[0] >> 6;
   // Padding
@@ -219,17 +220,18 @@ bool RtpHeaderParser::Parse(RTPHeader* h
   header->ssrc           = SSRC;
   header->numCSRCs       = CC;
   header->paddingLength  = P ? *(_ptrRTPDataEnd - 1) : 0;
 
   // 12 == sizeof(RFC rtp header) == kRtpMinParseLength, each CSRC=4 bytes
   header->headerLength   = 12 + (CC * 4);
   // not a full validation, just safety against underflow.  Padding must
   // start after the header.  We can have 0 payload bytes left, note.
-  if (header->paddingLength + header->headerLength > (size_t) length) {
+  if (!secured &&
+      (header->paddingLength + header->headerLength > (size_t) length)) {
     return false;
   }
 
   for (uint8_t i = 0; i < CC; ++i) {
     uint32_t CSRC = ByteReader<uint32_t>::ReadBigEndian(ptr);
     ptr += 4;
     header->arrOfCSRCs[i] = CSRC;
   }
--- a/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.h
+++ b/media/webrtc/trunk/webrtc/modules/rtp_rtcp/source/rtp_utility.h
@@ -44,17 +44,18 @@ size_t Word32Align(size_t size);
 class RtpHeaderParser {
  public:
   RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength);
   ~RtpHeaderParser();
 
   bool RTCP() const;
   bool ParseRtcp(RTPHeader* header) const;
   bool Parse(RTPHeader* parsedPacket,
-             RtpHeaderExtensionMap* ptrExtensionMap = nullptr) const;
+             RtpHeaderExtensionMap* ptrExtensionMap = nullptr,
+             bool secured = false) const;
 
  private:
   void ParseOneByteExtensionHeader(RTPHeader* parsedPacket,
                                    const RtpHeaderExtensionMap* ptrExtensionMap,
                                    const uint8_t* ptrRTPDataExtensionEnd,
                                    const uint8_t* ptr) const;
 
   const uint8_t* const _ptrRTPDataBegin;