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.

72 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2017 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 <algorithm>
  11. #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
  12. #include "modules/rtp_rtcp/include/ulpfec_receiver.h"
  13. #include "modules/rtp_rtcp/source/byte_io.h"
  14. #include "modules/rtp_rtcp/source/rtp_packet_received.h"
  15. #include "test/fuzzers/fuzz_data_helper.h"
  16. namespace webrtc {
  17. namespace {
  18. class DummyCallback : public RecoveredPacketReceiver {
  19. void OnRecoveredPacket(const uint8_t* packet, size_t length) override {}
  20. };
  21. } // namespace
  22. void FuzzOneInput(const uint8_t* data, size_t size) {
  23. constexpr size_t kMinDataNeeded = 12;
  24. if (size < kMinDataNeeded || size > 2000) {
  25. return;
  26. }
  27. uint32_t ulpfec_ssrc = ByteReader<uint32_t>::ReadLittleEndian(data + 0);
  28. uint16_t ulpfec_seq_num = ByteReader<uint16_t>::ReadLittleEndian(data + 4);
  29. uint32_t media_ssrc = ByteReader<uint32_t>::ReadLittleEndian(data + 6);
  30. uint16_t media_seq_num = ByteReader<uint16_t>::ReadLittleEndian(data + 10);
  31. DummyCallback callback;
  32. std::unique_ptr<UlpfecReceiver> receiver(
  33. UlpfecReceiver::Create(ulpfec_ssrc, &callback, {}));
  34. test::FuzzDataHelper fuzz_data(rtc::MakeArrayView(data, size));
  35. while (fuzz_data.CanReadBytes(kMinDataNeeded)) {
  36. size_t packet_length = kRtpHeaderSize + fuzz_data.Read<uint8_t>();
  37. auto raw_packet = fuzz_data.ReadByteArray(packet_length);
  38. RtpPacket parsed_packet;
  39. if (!parsed_packet.Parse(raw_packet))
  40. continue;
  41. // Overwrite the fields for the sequence number and SSRC with
  42. // consistent values for either a received UlpFEC packet or received media
  43. // packet. (We're still relying on libfuzzer to manage to generate packet
  44. // headers that interact together; this just ensures that we have two
  45. // consistent streams).
  46. if (fuzz_data.ReadOrDefaultValue<uint8_t>(0) % 2 == 0) {
  47. // Simulate UlpFEC packet.
  48. parsed_packet.SetSequenceNumber(ulpfec_seq_num++);
  49. parsed_packet.SetSsrc(ulpfec_ssrc);
  50. } else {
  51. // Simulate media packet.
  52. parsed_packet.SetSequenceNumber(media_seq_num++);
  53. parsed_packet.SetSsrc(media_ssrc);
  54. }
  55. receiver->AddReceivedRedPacket(parsed_packet, 0);
  56. }
  57. receiver->ProcessReceivedFec();
  58. }
  59. } // namespace webrtc