From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/test/fuzzers/BUILD.gn | 38 ++++++++++- .../fuzzers/audio_processing_configs_fuzzer.cc | 17 +++-- .../receive-side-cc/testcase-5414098152390656 | Bin 0 -> 87 bytes .../test/fuzzers/rtp_format_h264_fuzzer.cc | 75 +++++++++++++++++++++ .../test/fuzzers/rtp_format_vp8_fuzzer.cc | 73 ++++++++++++++++++++ .../test/fuzzers/rtp_format_vp9_fuzzer.cc | 73 ++++++++++++++++++++ 6 files changed, 267 insertions(+), 9 deletions(-) create mode 100644 third_party/libwebrtc/test/fuzzers/corpora/receive-side-cc/testcase-5414098152390656 create mode 100644 third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc create mode 100644 third_party/libwebrtc/test/fuzzers/rtp_format_vp8_fuzzer.cc create mode 100644 third_party/libwebrtc/test/fuzzers/rtp_format_vp9_fuzzer.cc (limited to 'third_party/libwebrtc/test/fuzzers') diff --git a/third_party/libwebrtc/test/fuzzers/BUILD.gn b/third_party/libwebrtc/test/fuzzers/BUILD.gn index 43e9a5e922..083c20c6f4 100644 --- a/third_party/libwebrtc/test/fuzzers/BUILD.gn +++ b/third_party/libwebrtc/test/fuzzers/BUILD.gn @@ -238,6 +238,36 @@ webrtc_fuzzer_test("rtp_packetizer_av1_fuzzer") { ] } +webrtc_fuzzer_test("rtp_format_h264_fuzzer") { + sources = [ "rtp_format_h264_fuzzer.cc" ] + deps = [ + "../../api/video:video_frame_type", + "../../modules/rtp_rtcp:rtp_rtcp", + "../../modules/rtp_rtcp:rtp_rtcp_format", + "../../rtc_base:checks", + ] +} + +webrtc_fuzzer_test("rtp_format_vp8_fuzzer") { + sources = [ "rtp_format_vp8_fuzzer.cc" ] + deps = [ + "../../api/video:video_frame_type", + "../../modules/rtp_rtcp:rtp_rtcp", + "../../modules/rtp_rtcp:rtp_rtcp_format", + "../../rtc_base:checks", + ] +} + +webrtc_fuzzer_test("rtp_format_vp9_fuzzer") { + sources = [ "rtp_format_vp9_fuzzer.cc" ] + deps = [ + "../../api/video:video_frame_type", + "../../modules/rtp_rtcp:rtp_rtcp", + "../../modules/rtp_rtcp:rtp_rtcp_format", + "../../rtc_base:checks", + ] +} + webrtc_fuzzer_test("receive_side_congestion_controller_fuzzer") { sources = [ "receive_side_congestion_controller_fuzzer.cc" ] deps = [ @@ -248,6 +278,7 @@ webrtc_fuzzer_test("receive_side_congestion_controller_fuzzer") { "../../modules/rtp_rtcp:rtp_rtcp_format", "../../system_wrappers", ] + seed_corpus = "corpora/receive-side-cc" } rtc_library("audio_decoder_fuzzer") { @@ -469,6 +500,7 @@ webrtc_fuzzer_test("audio_processing_fuzzer") { "../../api:scoped_refptr", "../../api/audio:aec3_factory", "../../api/audio:echo_detector_creator", + "../../api/task_queue", "../../api/task_queue:default_task_queue_factory", "../../modules/audio_processing", "../../modules/audio_processing:api", @@ -478,11 +510,13 @@ webrtc_fuzzer_test("audio_processing_fuzzer") { "../../modules/audio_processing/aec_dump", "../../modules/audio_processing/aec_dump:aec_dump_impl", "../../rtc_base:macromagic", - "../../rtc_base:rtc_task_queue", "../../rtc_base:safe_minmax", "../../system_wrappers:field_trial", ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/base:nullability", + "//third_party/abseil-cpp/absl/memory", + ] seed_corpus = "corpora/audio_processing-corpus" } diff --git a/third_party/libwebrtc/test/fuzzers/audio_processing_configs_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/audio_processing_configs_fuzzer.cc index 331a373f4e..93bce2f2e7 100644 --- a/third_party/libwebrtc/test/fuzzers/audio_processing_configs_fuzzer.cc +++ b/third_party/libwebrtc/test/fuzzers/audio_processing_configs_fuzzer.cc @@ -11,16 +11,17 @@ #include #include +#include "absl/base/nullability.h" #include "absl/memory/memory.h" #include "api/audio/echo_canceller3_factory.h" #include "api/audio/echo_detector_creator.h" #include "api/task_queue/default_task_queue_factory.h" +#include "api/task_queue/task_queue_base.h" #include "modules/audio_processing/aec_dump/aec_dump_factory.h" #include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" #include "rtc_base/arraysize.h" #include "rtc_base/numerics/safe_minmax.h" -#include "rtc_base/task_queue.h" #include "system_wrappers/include/field_trial.h" #include "test/fuzzers/audio_processing_fuzzer_helper.h" #include "test/fuzzers/fuzz_data_helper.h" @@ -33,9 +34,10 @@ const std::string kFieldTrialNames[] = { "WebRTC-Aec3ShortHeadroomKillSwitch", }; -rtc::scoped_refptr CreateApm(test::FuzzDataHelper* fuzz_data, - std::string* field_trial_string, - rtc::TaskQueue* worker_queue) { +rtc::scoped_refptr CreateApm( + test::FuzzDataHelper* fuzz_data, + std::string* field_trial_string, + absl::Nonnull worker_queue) { // Parse boolean values for optionally enabling different // configurable public components of APM. bool use_ts = fuzz_data->ReadOrDefaultValue(true); @@ -134,9 +136,10 @@ void FuzzOneInput(const uint8_t* data, size_t size) { // for field_trial.h. Hence it's created here and not in CreateApm. std::string field_trial_string = ""; - rtc::TaskQueue worker_queue(GetTaskQueueFactory()->CreateTaskQueue( - "rtc-low-prio", rtc::TaskQueue::Priority::LOW)); - auto apm = CreateApm(&fuzz_data, &field_trial_string, &worker_queue); + std::unique_ptr worker_queue = + GetTaskQueueFactory()->CreateTaskQueue("rtc-low-prio", + TaskQueueFactory::Priority::LOW); + auto apm = CreateApm(&fuzz_data, &field_trial_string, worker_queue.get()); if (apm) { FuzzAudioProcessing(&fuzz_data, std::move(apm)); diff --git a/third_party/libwebrtc/test/fuzzers/corpora/receive-side-cc/testcase-5414098152390656 b/third_party/libwebrtc/test/fuzzers/corpora/receive-side-cc/testcase-5414098152390656 new file mode 100644 index 0000000000..98c423cdc2 Binary files /dev/null and b/third_party/libwebrtc/test/fuzzers/corpora/receive-side-cc/testcase-5414098152390656 differ diff --git a/third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc new file mode 100644 index 0000000000..ddf2ca9d3d --- /dev/null +++ b/third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include +#include + +#include "api/video/video_frame_type.h" +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "modules/rtp_rtcp/source/rtp_format_h264.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" +#include "rtc_base/checks.h" +#include "test/fuzzers/fuzz_data_helper.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + test::FuzzDataHelper fuzz_input(rtc::MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits; + limits.max_payload_len = 1200; + // Read uint8_t to be sure reduction_lens are much smaller than + // max_payload_len and thus limits structure is valid. + limits.first_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.single_packet_reduction_len = + fuzz_input.ReadOrDefaultValue(0); + const H264PacketizationMode kPacketizationModes[] = { + H264PacketizationMode::NonInterleaved, + H264PacketizationMode::SingleNalUnit}; + + H264PacketizationMode packetization_mode = + fuzz_input.SelectOneOf(kPacketizationModes); + + // Main function under test: RtpPacketizerH264's constructor. + RtpPacketizerH264 packetizer(fuzz_input.ReadByteArray(fuzz_input.BytesLeft()), + limits, packetization_mode); + + size_t num_packets = packetizer.NumPackets(); + if (num_packets == 0) { + return; + } + // When packetization was successful, validate NextPacket function too. + // While at it, check that packets respect the payload size limits. + RtpPacketToSend rtp_packet(nullptr); + // Single packet. + if (num_packets == 1) { + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.single_packet_reduction_len); + return; + } + // First packet. + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.first_packet_reduction_len); + // Middle packets. + for (size_t i = 1; i < num_packets - 1; ++i) { + rtp_packet.Clear(); + RTC_CHECK(packetizer.NextPacket(&rtp_packet)) + << "Failed to get packet#" << i; + RTC_CHECK_LE(rtp_packet.payload_size(), limits.max_payload_len) + << "Packet #" << i << " exceeds it's limit"; + } + // Last packet. + rtp_packet.Clear(); + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.last_packet_reduction_len); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/test/fuzzers/rtp_format_vp8_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_format_vp8_fuzzer.cc new file mode 100644 index 0000000000..c3c055de0f --- /dev/null +++ b/third_party/libwebrtc/test/fuzzers/rtp_format_vp8_fuzzer.cc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include +#include + +#include "api/video/video_frame_type.h" +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "modules/rtp_rtcp/source/rtp_format_vp8.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" +#include "rtc_base/checks.h" +#include "test/fuzzers/fuzz_data_helper.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + test::FuzzDataHelper fuzz_input(rtc::MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits; + limits.max_payload_len = 1200; + // Read uint8_t to be sure reduction_lens are much smaller than + // max_payload_len and thus limits structure is valid. + limits.first_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.single_packet_reduction_len = + fuzz_input.ReadOrDefaultValue(0); + + RTPVideoHeaderVP8 hdr_info; + hdr_info.InitRTPVideoHeaderVP8(); + uint16_t picture_id = fuzz_input.ReadOrDefaultValue(0); + hdr_info.pictureId = + picture_id >= 0x8000 ? kNoPictureId : picture_id & 0x7fff; + + // Main function under test: RtpPacketizerVp8's constructor. + RtpPacketizerVp8 packetizer(fuzz_input.ReadByteArray(fuzz_input.BytesLeft()), + limits, hdr_info); + + size_t num_packets = packetizer.NumPackets(); + if (num_packets == 0) { + return; + } + // When packetization was successful, validate NextPacket function too. + // While at it, check that packets respect the payload size limits. + RtpPacketToSend rtp_packet(nullptr); + // Single packet. + if (num_packets == 1) { + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.single_packet_reduction_len); + return; + } + // First packet. + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.first_packet_reduction_len); + // Middle packets. + for (size_t i = 1; i < num_packets - 1; ++i) { + RTC_CHECK(packetizer.NextPacket(&rtp_packet)) + << "Failed to get packet#" << i; + RTC_CHECK_LE(rtp_packet.payload_size(), limits.max_payload_len) + << "Packet #" << i << " exceeds it's limit"; + } + // Last packet. + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.last_packet_reduction_len); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/test/fuzzers/rtp_format_vp9_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_format_vp9_fuzzer.cc new file mode 100644 index 0000000000..3b5e67f697 --- /dev/null +++ b/third_party/libwebrtc/test/fuzzers/rtp_format_vp9_fuzzer.cc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include +#include + +#include "api/video/video_frame_type.h" +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "modules/rtp_rtcp/source/rtp_format_vp9.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" +#include "rtc_base/checks.h" +#include "test/fuzzers/fuzz_data_helper.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + test::FuzzDataHelper fuzz_input(rtc::MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits; + limits.max_payload_len = 1200; + // Read uint8_t to be sure reduction_lens are much smaller than + // max_payload_len and thus limits structure is valid. + limits.first_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue(0); + limits.single_packet_reduction_len = + fuzz_input.ReadOrDefaultValue(0); + + RTPVideoHeaderVP9 hdr_info; + hdr_info.InitRTPVideoHeaderVP9(); + uint16_t picture_id = fuzz_input.ReadOrDefaultValue(0); + hdr_info.picture_id = + picture_id >= 0x8000 ? kNoPictureId : picture_id & 0x7fff; + + // Main function under test: RtpPacketizerVp9's constructor. + RtpPacketizerVp9 packetizer(fuzz_input.ReadByteArray(fuzz_input.BytesLeft()), + limits, hdr_info); + + size_t num_packets = packetizer.NumPackets(); + if (num_packets == 0) { + return; + } + // When packetization was successful, validate NextPacket function too. + // While at it, check that packets respect the payload size limits. + RtpPacketToSend rtp_packet(nullptr); + // Single packet. + if (num_packets == 1) { + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.single_packet_reduction_len); + return; + } + // First packet. + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.first_packet_reduction_len); + // Middle packets. + for (size_t i = 1; i < num_packets - 1; ++i) { + RTC_CHECK(packetizer.NextPacket(&rtp_packet)) + << "Failed to get packet#" << i; + RTC_CHECK_LE(rtp_packet.payload_size(), limits.max_payload_len) + << "Packet #" << i << " exceeds it's limit"; + } + // Last packet. + RTC_CHECK(packetizer.NextPacket(&rtp_packet)); + RTC_CHECK_LE(rtp_packet.payload_size(), + limits.max_payload_len - limits.last_packet_reduction_len); +} +} // namespace webrtc -- cgit v1.2.3