tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 83bcf0993368d0177a21827faca6a17b0f21c676
parent 54dea0ee5e9abc2e11b42d0e02c2183f5a610256
Author: Dan Baker <dbaker@mozilla.com>
Date:   Thu, 23 Oct 2025 17:03:34 -0600

Bug 1995393 - Vendor libwebrtc from aed2936b7a

Upstream commit: https://webrtc.googlesource.com/src/+/aed2936b7a5988167a4818b5a25c22a384ebc4c2
    Refactor RtpPacketizer fuzzers - move identical code into helper functions

    This simplifies adding fuzzers for new packetizers.
    Add (failing) fuzzer for H265 packetizer.

    Bug: webrtc:439305142
    Change-Id: Ifd4515c539ca7ff3247852f92adaf20992addb05
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/404966
    Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
    Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45370}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0102.patch | 4++--
Mthird_party/libwebrtc/test/fuzzers/BUILD.gn | 35+++++++++++++++++++++++------------
Mthird_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc | 47+++++------------------------------------------
Mthird_party/libwebrtc/test/fuzzers/rtp_format_vp8_fuzzer.cc | 42+++---------------------------------------
Mthird_party/libwebrtc/test/fuzzers/rtp_format_vp9_fuzzer.cc | 44++++----------------------------------------
Mthird_party/libwebrtc/test/fuzzers/rtp_packetizer_av1_fuzzer.cc | 45+++++----------------------------------------
Athird_party/libwebrtc/test/fuzzers/rtp_packetizer_h265_fuzzer.cc | 31+++++++++++++++++++++++++++++++
Mthird_party/libwebrtc/test/fuzzers/utils/BUILD.gn | 13+++++++++++++
Athird_party/libwebrtc/test/fuzzers/utils/validate_rtp_packetizer.cc | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Athird_party/libwebrtc/test/fuzzers/utils/validate_rtp_packetizer.h | 29+++++++++++++++++++++++++++++
11 files changed, 191 insertions(+), 177 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-23T23:00:17.260638+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-23T23:03:20.759830+00:00. # base of lastest vendoring -496b7b5a10 +aed2936b7a diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch @@ -782,7 +782,7 @@ index f3d2496773..28ac646821 100644 deps = [ ":google_test_runner_delegate" ] } diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn -index ae891d22bd..4f2e3cc266 100644 +index 0271277265..a9117c962d 100644 --- a/test/fuzzers/BUILD.gn +++ b/test/fuzzers/BUILD.gn @@ -6,7 +6,7 @@ @@ -794,7 +794,7 @@ index ae891d22bd..4f2e3cc266 100644 import("//testing/libfuzzer/fuzzer_test.gni") import("../../webrtc.gni") -@@ -73,7 +73,7 @@ template("webrtc_fuzzer_test") { +@@ -78,7 +78,7 @@ template("webrtc_fuzzer_test") { } if (!build_with_chromium && is_clang) { diff --git a/third_party/libwebrtc/test/fuzzers/BUILD.gn b/third_party/libwebrtc/test/fuzzers/BUILD.gn @@ -39,7 +39,12 @@ rtc_library("fuzz_data_helper") { "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:checks", ] - visibility = [ ":*" ] # Only targets in this file can depend on this. + + # Only fuzzer targets can depend on this. + visibility = [ + ":*", + "utils:*", + ] } set_defaults("webrtc_fuzzer_test") { @@ -270,20 +275,29 @@ webrtc_fuzzer_test("rtp_packetizer_av1_fuzzer") { "../../api:array_view", "../../api/video:video_frame_type", "../../modules/rtp_rtcp", - "../../modules/rtp_rtcp:rtp_rtcp_format", - "../../rtc_base:checks", + "utils:validate_rtp_packetizer", ] } +if (rtc_use_h265) { + webrtc_fuzzer_test("rtp_packetizer_h265_fuzzer") { + sources = [ "rtp_packetizer_h265_fuzzer.cc" ] + deps = [ + "../../api:array_view", + "../../api/video:video_frame_type", + "../../modules/rtp_rtcp", + "utils:validate_rtp_packetizer", + ] + } +} + webrtc_fuzzer_test("rtp_format_h264_fuzzer") { sources = [ "rtp_format_h264_fuzzer.cc" ] deps = [ "../../api:array_view", - "../../api/video:video_frame_type", "../../modules/rtp_rtcp", - "../../modules/rtp_rtcp:rtp_rtcp_format", "../../modules/video_coding:codec_globals_headers", - "../../rtc_base:checks", + "utils:validate_rtp_packetizer", ] } @@ -291,11 +305,9 @@ webrtc_fuzzer_test("rtp_format_vp8_fuzzer") { sources = [ "rtp_format_vp8_fuzzer.cc" ] deps = [ "../../api:array_view", - "../../api/video:video_frame_type", "../../modules/rtp_rtcp", - "../../modules/rtp_rtcp:rtp_rtcp_format", "../../modules/video_coding:codec_globals_headers", - "../../rtc_base:checks", + "utils:validate_rtp_packetizer", ] } @@ -303,11 +315,9 @@ webrtc_fuzzer_test("rtp_format_vp9_fuzzer") { sources = [ "rtp_format_vp9_fuzzer.cc" ] deps = [ "../../api:array_view", - "../../api/video:video_frame_type", "../../modules/rtp_rtcp", - "../../modules/rtp_rtcp:rtp_rtcp_format", "../../modules/video_coding:codec_globals_headers", - "../../rtc_base:checks", + "utils:validate_rtp_packetizer", ] } @@ -883,6 +893,7 @@ group("fuzzers") { deps += [ ":h265_bitstream_parser_fuzzer", ":h265_depacketizer_fuzzer", + ":rtp_packetizer_h265_fuzzer", ] } diff --git a/third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_format_h264_fuzzer.cc @@ -13,23 +13,16 @@ #include "api/array_view.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 "modules/video_coding/codecs/h264/include/h264_globals.h" -#include "rtc_base/checks.h" #include "test/fuzzers/fuzz_data_helper.h" +#include "test/fuzzers/utils/validate_rtp_packetizer.h" namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { - test::FuzzDataHelper fuzz_input(webrtc::MakeArrayView(data, size)); + test::FuzzDataHelper fuzz_input(MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits = ReadPayloadSizeLimits(fuzz_input); - 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<uint8_t>(0); - limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0); - limits.single_packet_reduction_len = - fuzz_input.ReadOrDefaultValue<uint8_t>(0); const H264PacketizationMode kPacketizationModes[] = { H264PacketizationMode::NonInterleaved, H264PacketizationMode::SingleNalUnit}; @@ -41,36 +34,6 @@ void FuzzOneInput(const uint8_t* data, size_t size) { 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); + ValidateRtpPacketizer(limits, packetizer); } } // 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 @@ -13,24 +13,16 @@ #include "api/array_view.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 "modules/video_coding/codecs/interface/common_constants.h" #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" -#include "rtc_base/checks.h" #include "test/fuzzers/fuzz_data_helper.h" +#include "test/fuzzers/utils/validate_rtp_packetizer.h" namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { test::FuzzDataHelper fuzz_input(webrtc::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<uint8_t>(0); - limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0); - limits.single_packet_reduction_len = - fuzz_input.ReadOrDefaultValue<uint8_t>(0); + RtpPacketizer::PayloadSizeLimits limits = ReadPayloadSizeLimits(fuzz_input); RTPVideoHeaderVP8 hdr_info; hdr_info.InitRTPVideoHeaderVP8(); @@ -42,34 +34,6 @@ void FuzzOneInput(const uint8_t* data, size_t size) { 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); + ValidateRtpPacketizer(limits, packetizer); } } // 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 @@ -13,24 +13,16 @@ #include "api/array_view.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 "modules/video_coding/codecs/interface/common_constants.h" #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" -#include "rtc_base/checks.h" #include "test/fuzzers/fuzz_data_helper.h" +#include "test/fuzzers/utils/validate_rtp_packetizer.h" namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { - test::FuzzDataHelper fuzz_input(webrtc::MakeArrayView(data, size)); + test::FuzzDataHelper fuzz_input(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<uint8_t>(0); - limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0); - limits.single_packet_reduction_len = - fuzz_input.ReadOrDefaultValue<uint8_t>(0); + RtpPacketizer::PayloadSizeLimits limits = ReadPayloadSizeLimits(fuzz_input); RTPVideoHeaderVP9 hdr_info; hdr_info.InitRTPVideoHeaderVP9(); @@ -42,34 +34,6 @@ void FuzzOneInput(const uint8_t* data, size_t size) { 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); + ValidateRtpPacketizer(limits, packetizer); } } // namespace webrtc diff --git a/third_party/libwebrtc/test/fuzzers/rtp_packetizer_av1_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_packetizer_av1_fuzzer.cc @@ -13,23 +13,16 @@ #include "api/array_view.h" #include "api/video/video_frame_type.h" #include "modules/rtp_rtcp/source/rtp_format.h" -#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "modules/rtp_rtcp/source/rtp_packetizer_av1.h" -#include "rtc_base/checks.h" #include "test/fuzzers/fuzz_data_helper.h" +#include "test/fuzzers/utils/validate_rtp_packetizer.h" namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { - test::FuzzDataHelper fuzz_input(webrtc::MakeArrayView(data, size)); + test::FuzzDataHelper fuzz_input(MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits = ReadPayloadSizeLimits(fuzz_input); - 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<uint8_t>(0); - limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0); - limits.single_packet_reduction_len = - fuzz_input.ReadOrDefaultValue<uint8_t>(0); const VideoFrameType kFrameTypes[] = {VideoFrameType::kVideoFrameKey, VideoFrameType::kVideoFrameDelta}; VideoFrameType frame_type = fuzz_input.SelectOneOf(kFrameTypes); @@ -39,34 +32,6 @@ void FuzzOneInput(const uint8_t* data, size_t size) { limits, frame_type, /*is_last_frame_in_picture=*/true); - 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); + ValidateRtpPacketizer(limits, packetizer); } } // namespace webrtc diff --git a/third_party/libwebrtc/test/fuzzers/rtp_packetizer_h265_fuzzer.cc b/third_party/libwebrtc/test/fuzzers/rtp_packetizer_h265_fuzzer.cc @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 <cstddef> +#include <cstdint> + +#include "modules/rtp_rtcp/source/rtp_packetizer_h265.h" +#include "test/fuzzers/fuzz_data_helper.h" +#include "test/fuzzers/utils/validate_rtp_packetizer.h" + +namespace webrtc { + +void FuzzOneInput(const uint8_t* data, size_t size) { + test::FuzzDataHelper fuzz_input(MakeArrayView(data, size)); + + RtpPacketizer::PayloadSizeLimits limits = ReadPayloadSizeLimits(fuzz_input); + + // Main function under test: RtpPacketizerH265's constructor. + RtpPacketizerH265 packetizer(fuzz_input.ReadByteArray(fuzz_input.BytesLeft()), + limits); + + ValidateRtpPacketizer(limits, packetizer); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/test/fuzzers/utils/BUILD.gn b/third_party/libwebrtc/test/fuzzers/utils/BUILD.gn @@ -47,3 +47,16 @@ rtc_library("rtp_replayer") { "//third_party/abseil-cpp/absl/memory", ] } + +rtc_library("validate_rtp_packetizer") { + testonly = true + sources = [ + "validate_rtp_packetizer.cc", + "validate_rtp_packetizer.h", + ] + deps = [ + "..:fuzz_data_helper", + "../../../modules/rtp_rtcp", + "../../../modules/rtp_rtcp:rtp_rtcp_format", + ] +} diff --git a/third_party/libwebrtc/test/fuzzers/utils/validate_rtp_packetizer.cc b/third_party/libwebrtc/test/fuzzers/utils/validate_rtp_packetizer.cc @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 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 "test/fuzzers/utils/validate_rtp_packetizer.h" + +#include <cstddef> + +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" + +namespace webrtc { + +RtpPacketizer::PayloadSizeLimits ReadPayloadSizeLimits( + test::FuzzDataHelper& fuzz_input) { + 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<uint8_t>(0); + limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0); + limits.single_packet_reduction_len = + fuzz_input.ReadOrDefaultValue<uint8_t>(0); + return limits; +} + +void ValidateRtpPacketizer(const RtpPacketizer::PayloadSizeLimits& limits, + RtpPacketizer& packetizer) { + 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/utils/validate_rtp_packetizer.h b/third_party/libwebrtc/test/fuzzers/utils/validate_rtp_packetizer.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 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. + */ + +#ifndef TEST_FUZZERS_UTILS_VALIDATE_RTP_PACKETIZER_H_ +#define TEST_FUZZERS_UTILS_VALIDATE_RTP_PACKETIZER_H_ + +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "test/fuzzers/fuzz_data_helper.h" + +namespace webrtc { + +// Generates valid `RtpPacketizer::PayloadSizeLimits` from the `fuzz_input`. +RtpPacketizer::PayloadSizeLimits ReadPayloadSizeLimits( + test::FuzzDataHelper& fuzz_input); + +// RTC_CHECKs if `rtp_packetizer` created packets with respect to the `limits`. +void ValidateRtpPacketizer(const RtpPacketizer::PayloadSizeLimits& limits, + RtpPacketizer& rtp_packetizer); + +} // namespace webrtc + +#endif // TEST_FUZZERS_UTILS_VALIDATE_RTP_PACKETIZER_H_