You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <bitset>
  11. #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
  12. #include "modules/rtp_rtcp/source/rtp_packet_received.h"
  13. #include "modules/rtp_rtcp/source/rtp_utility.h"
  14. namespace webrtc {
  15. // We decide which header extensions to register by reading four bytes
  16. // from the beginning of |data| and interpreting it as a bitmask over
  17. // the RTPExtensionType enum. This assert ensures four bytes are enough.
  18. static_assert(kRtpExtensionNumberOfExtensions <= 32,
  19. "Insufficient bits read to configure all header extensions. Add "
  20. "an extra byte and update the switches.");
  21. void FuzzOneInput(const uint8_t* data, size_t size) {
  22. if (size <= 4)
  23. return;
  24. // Don't use the configuration byte as part of the packet.
  25. std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
  26. data += 4;
  27. size -= 4;
  28. RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true);
  29. // Start at local_id = 1 since 0 is an invalid extension id.
  30. int local_id = 1;
  31. // Skip i = 0 since it maps to kRtpExtensionNone.
  32. for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) {
  33. RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
  34. if (extensionMask[i]) {
  35. // Extensions are registered with an ID, which you signal to the
  36. // peer so they know what to expect. This code only cares about
  37. // parsing so the value of the ID isn't relevant.
  38. extensions.RegisterByType(local_id++, extension_type);
  39. }
  40. }
  41. RTPHeader rtp_header;
  42. RtpUtility::RtpHeaderParser rtp_parser(data, size);
  43. rtp_parser.Parse(&rtp_header, &extensions);
  44. }
  45. } // namespace webrtc