diff --git a/worker/fuzzer/include/RTC/FuzzerRateCalculator.hpp b/worker/fuzzer/include/RTC/FuzzerRateCalculator.hpp new file mode 100644 index 0000000000..c7386bb3db --- /dev/null +++ b/worker/fuzzer/include/RTC/FuzzerRateCalculator.hpp @@ -0,0 +1,17 @@ +#ifndef MS_FUZZER_RTC_RATE_CALCULATOR_HPP +#define MS_FUZZER_RTC_RATE_CALCULATOR_HPP + +#include "common.hpp" + +namespace Fuzzer +{ + namespace RTC + { + namespace RateCalculator + { + void Fuzz(const uint8_t* data, size_t len); + } + } // namespace RTC +} // namespace Fuzzer + +#endif diff --git a/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp b/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp new file mode 100644 index 0000000000..863fc0420b --- /dev/null +++ b/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp @@ -0,0 +1,28 @@ +#include "RTC/FuzzerRateCalculator.hpp" +#include "DepLibUV.hpp" +#include "Utils.hpp" +#include "RTC/RateCalculator.hpp" +#include "RTC/RtpPacket.hpp" // RTC::MtuSize + +::RTC::RateCalculator rateCalculator; + +void Fuzzer::RTC::RateCalculator::Fuzz(const uint8_t* data, size_t len) +{ + // We need at least 2 bytes of |data|. + if (len < 2) + { + return; + } + + auto size = + static_cast(Utils::Crypto::GetRandomUInt(0u, static_cast(::RTC::MtuSize))); + uint64_t nowMs = DepLibUV::GetTimeMs(); + + rateCalculator.Update(size, nowMs); + + // Only get rate from time to time. + if (Utils::Byte::Get2Bytes(data, 0) % 100 == 0) + { + rateCalculator.GetRate(nowMs); + } +} diff --git a/worker/fuzzer/src/fuzzer.cpp b/worker/fuzzer/src/fuzzer.cpp index d51422b103..7c5c4dc996 100644 --- a/worker/fuzzer/src/fuzzer.cpp +++ b/worker/fuzzer/src/fuzzer.cpp @@ -16,6 +16,7 @@ #include "RTC/Codecs/FuzzerVP9.hpp" #include "RTC/DtlsTransport.hpp" #include "RTC/FuzzerDtlsTransport.hpp" +#include "RTC/FuzzerRateCalculator.hpp" #include "RTC/FuzzerRtpPacket.hpp" #include "RTC/FuzzerRtpRetransmissionBuffer.hpp" #include "RTC/FuzzerRtpStreamSend.hpp" @@ -35,7 +36,9 @@ bool fuzzRtcp = false; bool fuzzCodecs = false; bool fuzzUtils = false; -int Init(); +// This Init() function must be declared static, otherwise linking will fail if +// another source file defines same non static Init() function. +static int Init(); extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len) { @@ -61,6 +64,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len) Fuzzer::RTC::RtpStreamSend::Fuzz(data, len); Fuzzer::RTC::RtpRetransmissionBuffer::Fuzz(data, len); Fuzzer::RTC::SeqManager::Fuzz(data, len); + Fuzzer::RTC::RateCalculator::Fuzz(data, len); } if (fuzzRtcp) diff --git a/worker/meson.build b/worker/meson.build index f4d24f5958..1be338815b 100644 --- a/worker/meson.build +++ b/worker/meson.build @@ -432,6 +432,7 @@ executable( 'fuzzer/src/fuzzer.cpp', 'fuzzer/src/FuzzerUtils.cpp', 'fuzzer/src/RTC/FuzzerDtlsTransport.cpp', + 'fuzzer/src/RTC/FuzzerRateCalculator.cpp', 'fuzzer/src/RTC/FuzzerRtpPacket.cpp', 'fuzzer/src/RTC/FuzzerRtpRetransmissionBuffer.cpp', 'fuzzer/src/RTC/FuzzerRtpStreamSend.cpp',