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.

66 lines
2.4 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 "modules/video_coding/frame_object.h"
  11. #include "modules/video_coding/packet_buffer.h"
  12. #include "system_wrappers/include/clock.h"
  13. #include "test/fuzzers/fuzz_data_helper.h"
  14. namespace webrtc {
  15. namespace {
  16. class NullCallback : public video_coding::OnAssembledFrameCallback {
  17. void OnAssembledFrame(std::unique_ptr<video_coding::RtpFrameObject> frame) {}
  18. };
  19. } // namespace
  20. void FuzzOneInput(const uint8_t* data, size_t size) {
  21. if (size > 200000) {
  22. return;
  23. }
  24. VCMPacket packet;
  25. NullCallback callback;
  26. SimulatedClock clock(0);
  27. video_coding::PacketBuffer packet_buffer(&clock, 8, 1024, &callback);
  28. test::FuzzDataHelper helper(rtc::ArrayView<const uint8_t>(data, size));
  29. while (helper.BytesLeft()) {
  30. // Complex types (e.g. non-POD-like types) can't be bit-wise fuzzed with
  31. // random data or it will put them in an invalid state. We therefore backup
  32. // their byte-patterns before the fuzzing and restore them after.
  33. uint8_t video_header_backup[sizeof(packet.video_header)];
  34. memcpy(&video_header_backup, &packet.video_header,
  35. sizeof(packet.video_header));
  36. uint8_t generic_descriptor_backup[sizeof(packet.generic_descriptor)];
  37. memcpy(&generic_descriptor_backup, &packet.generic_descriptor,
  38. sizeof(packet.generic_descriptor));
  39. uint8_t packet_info_backup[sizeof(packet.packet_info)];
  40. memcpy(&packet_info_backup, &packet.packet_info,
  41. sizeof(packet.packet_info));
  42. helper.CopyTo(&packet);
  43. memcpy(&packet.video_header, &video_header_backup,
  44. sizeof(packet.video_header));
  45. memcpy(&packet.generic_descriptor, &generic_descriptor_backup,
  46. sizeof(packet.generic_descriptor));
  47. memcpy(&packet.packet_info, &packet_info_backup,
  48. sizeof(packet.packet_info));
  49. // The packet buffer owns the payload of the packet.
  50. uint8_t payload_size;
  51. helper.CopyTo(&payload_size);
  52. packet.sizeBytes = payload_size;
  53. packet.dataPtr = new uint8_t[payload_size];
  54. packet_buffer.InsertPacket(&packet);
  55. }
  56. }
  57. } // namespace webrtc