| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
| 12 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 12 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
| 13 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 13 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 // We decide which header extensions to register by reading one byte | 17 // We decide which header extensions to register by reading two bytes |
| 18 // from the beginning of |data| and interpreting it as a bitmask over | 18 // from the beginning of |data| and interpreting it as a bitmask over |
| 19 // the RTPExtensionType enum. This assert ensures one byte is enough. | 19 // the RTPExtensionType enum. This assert ensures two bytes are enough. |
| 20 static_assert(kRtpExtensionNumberOfExtensions <= 8, | 20 static_assert(kRtpExtensionNumberOfExtensions <= 16, |
| 21 "Insufficient bits read to configure all header extensions. Add " | 21 "Insufficient bits read to configure all header extensions. Add " |
| 22 "an extra byte and update the switches."); | 22 "an extra byte and update the switches."); |
| 23 | 23 |
| 24 void FuzzOneInput(const uint8_t* data, size_t size) { | 24 void FuzzOneInput(const uint8_t* data, size_t size) { |
| 25 if (size <= 1) | 25 if (size <= 2) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 // Don't use the configuration byte as part of the packet. | 28 // Don't use the configuration bytes as part of the packet. |
| 29 std::bitset<8> extensionMask(data[0]); | 29 std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data)); |
| 30 data++; | 30 data += 2; |
| 31 size--; | 31 size -= 2; |
| 32 | 32 |
| 33 RtpPacketReceived::ExtensionManager extensions; | 33 RtpPacketReceived::ExtensionManager extensions; |
| 34 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { | 34 // Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid. |
| 35 for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) { |
| 35 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); | 36 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); |
| 36 if (extensionMask[i] && extension_type != kRtpExtensionNone) { | 37 if (extensionMask[i] && extension_type != kRtpExtensionNone) { |
| 37 // Extensions are registered with an ID, which you signal to the | 38 // Extensions are registered with an ID, which you signal to the |
| 38 // peer so they know what to expect. This code only cares about | 39 // peer so they know what to expect. This code only cares about |
| 39 // parsing so the value of the ID isn't relevant; we use i. | 40 // parsing so the value of the ID isn't relevant; we use i. |
| 40 extensions.Register(extension_type, i); | 41 extensions.RegisterByType(i, extension_type); |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 RtpPacketReceived packet(&extensions); | 45 RtpPacketReceived packet(&extensions); |
| 45 packet.Parse(data, size); | 46 packet.Parse(data, size); |
| 46 | 47 |
| 47 // Call packet accessors because they have extra checks. | 48 // Call packet accessors because they have extra checks. |
| 48 packet.Marker(); | 49 packet.Marker(); |
| 49 packet.PayloadType(); | 50 packet.PayloadType(); |
| 50 packet.SequenceNumber(); | 51 packet.SequenceNumber(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 packet.GetExtension<TransportSequenceNumber>(&seqnum); | 83 packet.GetExtension<TransportSequenceNumber>(&seqnum); |
| 83 break; | 84 break; |
| 84 case kRtpExtensionPlayoutDelay: | 85 case kRtpExtensionPlayoutDelay: |
| 85 PlayoutDelay playout; | 86 PlayoutDelay playout; |
| 86 packet.GetExtension<PlayoutDelayLimits>(&playout); | 87 packet.GetExtension<PlayoutDelayLimits>(&playout); |
| 87 break; | 88 break; |
| 88 case kRtpExtensionVideoContentType: | 89 case kRtpExtensionVideoContentType: |
| 89 VideoContentType content_type; | 90 VideoContentType content_type; |
| 90 packet.GetExtension<VideoContentTypeExtension>(&content_type); | 91 packet.GetExtension<VideoContentTypeExtension>(&content_type); |
| 91 break; | 92 break; |
| 93 case kRtpExtensionRtpStreamId: { |
| 94 std::string rsid; |
| 95 packet.GetExtension<RtpStreamId>(&rsid); |
| 96 break; |
| 97 } |
| 98 case kRtpExtensionRepairedRtpStreamId: { |
| 99 std::string rsid; |
| 100 packet.GetExtension<RepairedRtpStreamId>(&rsid); |
| 101 break; |
| 102 } |
| 92 } | 103 } |
| 93 } | 104 } |
| 94 } | 105 } |
| 95 } // namespace webrtc | 106 } // namespace webrtc |
| OLD | NEW |