 Chromium Code Reviews
 Chromium Code Reviews Issue 2072473002:
  Update the current RTP parser fuzzer to handle header extensions.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 2072473002:
  Update the current RTP parser fuzzer to handle header extensions.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| 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 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 
| 12 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | |
| 13 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | |
| 11 | 14 | 
| 12 namespace webrtc { | 15 namespace webrtc { | 
| 13 | 16 | 
| 17 // We decide which header extensions to register by reading one byte | |
| 18 // from the beginning of |data| and interpreting it as a bitmask over | |
| 19 // the RTPExtensionType enum. This ensures one byte is enough. | |
| 20 static_assert(kRtpExtensionNumberOfExtensions <= 1 * 8, | |
| 21 "Insufficient bits read to configure all header extensions. Add " | |
| 22 "an extra byte and update the switches."); | |
| 23 | |
| 14 void FuzzOneInput(const uint8_t* data, size_t size) { | 24 void FuzzOneInput(const uint8_t* data, size_t size) { | 
| 15 RtpPacketReceived packet; | 25 if (size <= 1) | 
| 26 return; | |
| 16 | 27 | 
| 28 // Don't use the configuration byte as part of the packet. | |
| 29 std::bitset<8> extensionMask(data[0]); | |
| 30 data++; | |
| 31 size--; | |
| 32 | |
| 33 RtpPacketReceived::ExtensionManager extensions; | |
| 34 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { | |
| 35 RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); | |
| 36 if (extensionMask[i] && extension_type != kRtpExtensionNone) { | |
| 37 // 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 // parsing so the value of the ID isn't relevant; we use i. | |
| 40 extensions.Register(extension_type, i); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 RtpPacketReceived packet(&extensions); | |
| 17 packet.Parse(data, size); | 45 packet.Parse(data, size); | 
| 18 | 46 | 
| 19 // Call packet accessors because they have extra checks. | 47 // Call packet accessors because they have extra checks. | 
| 20 packet.Marker(); | 48 packet.Marker(); | 
| 21 packet.PayloadType(); | 49 packet.PayloadType(); | 
| 22 packet.SequenceNumber(); | 50 packet.SequenceNumber(); | 
| 23 packet.Timestamp(); | 51 packet.Timestamp(); | 
| 24 packet.Ssrc(); | 52 packet.Ssrc(); | 
| 25 packet.Csrcs(); | 53 packet.Csrcs(); | 
| 54 | |
| 55 // Each extension has its own getter. Call all the ones we registered above. | |
| 
danilchap
2016/07/04 08:43:55
Update comment too since you do not check getting
 | |
| 56 for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { | |
| 57 switch (static_cast<RTPExtensionType>(i)) { | |
| 58 case kRtpExtensionNone: | |
| 59 case kRtpExtensionNumberOfExtensions: | |
| 60 break; | |
| 61 case kRtpExtensionTransmissionTimeOffset: | |
| 62 int32_t offset; | |
| 63 packet.GetExtension<TransmissionOffset>(&offset); | |
| 64 break; | |
| 65 case kRtpExtensionAudioLevel: | |
| 66 bool voice_activity; | |
| 67 uint8_t audio_level; | |
| 68 packet.GetExtension<AudioLevel>(&voice_activity, &audio_level); | |
| 69 break; | |
| 70 case kRtpExtensionAbsoluteSendTime: | |
| 71 uint32_t sendtime; | |
| 72 packet.GetExtension<AbsoluteSendTime>(&sendtime); | |
| 73 break; | |
| 74 case kRtpExtensionVideoRotation: | |
| 75 uint8_t rotation; | |
| 76 packet.GetExtension<VideoOrientation>(&rotation); | |
| 77 break; | |
| 78 case kRtpExtensionTransportSequenceNumber: | |
| 79 uint16_t seqnum; | |
| 80 packet.GetExtension<TransportSequenceNumber>(&seqnum); | |
| 81 break; | |
| 82 case kRtpExtensionPlayoutDelay: | |
| 83 // TODO(katrielc) Add this once it's written. | |
| 84 break; | |
| 85 } | |
| 86 } | |
| 26 } | 87 } | 
| 27 | |
| 28 } // namespace webrtc | 88 } // namespace webrtc | 
| 29 | |
| OLD | NEW |