Unverified 提交 fe0f7c40 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Add fuzzer for RateCalculator class (#1358)

上级 8d757bc5
#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
#include "RTC/FuzzerRateCalculator.hpp"
#include "DepLibUV.hpp"
#include "Utils.hpp"
#include "RTC/RateCalculator.hpp"
#include "RTC/RtpPacket.hpp" // RTC::MtuSize
static ::RTC::RateCalculator rateCalculator;
static uint64_t nowMs;
// This Init() function must be declared static, otherwise linking will fail if
// another source file defines same non static Init() function.
static int Init();
void Fuzzer::RTC::RateCalculator::Fuzz(const uint8_t* data, size_t len)
{
// Trick to initialize our stuff just once.
static int unused = Init();
// Avoid [-Wunused-variable].
unused++;
// We need at least 2 bytes of |data|.
if (len < 2)
{
return;
}
auto size =
static_cast<size_t>(Utils::Crypto::GetRandomUInt(0u, static_cast<uint32_t>(::RTC::MtuSize)));
nowMs += Utils::Crypto::GetRandomUInt(0u, 1000u);
rateCalculator.Update(size, nowMs);
// Only get rate from time to time.
if (Utils::Byte::Get2Bytes(data, 0) % 100 == 0)
{
rateCalculator.GetRate(nowMs);
}
}
int Init()
{
nowMs = DepLibUV::GetTimeMs();
return 0;
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "RTC/Codecs/FuzzerVP9.hpp" #include "RTC/Codecs/FuzzerVP9.hpp"
#include "RTC/DtlsTransport.hpp" #include "RTC/DtlsTransport.hpp"
#include "RTC/FuzzerDtlsTransport.hpp" #include "RTC/FuzzerDtlsTransport.hpp"
#include "RTC/FuzzerRateCalculator.hpp"
#include "RTC/FuzzerRtpPacket.hpp" #include "RTC/FuzzerRtpPacket.hpp"
#include "RTC/FuzzerRtpRetransmissionBuffer.hpp" #include "RTC/FuzzerRtpRetransmissionBuffer.hpp"
#include "RTC/FuzzerRtpStreamSend.hpp" #include "RTC/FuzzerRtpStreamSend.hpp"
...@@ -35,7 +36,9 @@ bool fuzzRtcp = false; ...@@ -35,7 +36,9 @@ bool fuzzRtcp = false;
bool fuzzCodecs = false; bool fuzzCodecs = false;
bool fuzzUtils = 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) 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) ...@@ -61,6 +64,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
Fuzzer::RTC::RtpStreamSend::Fuzz(data, len); Fuzzer::RTC::RtpStreamSend::Fuzz(data, len);
Fuzzer::RTC::RtpRetransmissionBuffer::Fuzz(data, len); Fuzzer::RTC::RtpRetransmissionBuffer::Fuzz(data, len);
Fuzzer::RTC::SeqManager::Fuzz(data, len); Fuzzer::RTC::SeqManager::Fuzz(data, len);
Fuzzer::RTC::RateCalculator::Fuzz(data, len);
} }
if (fuzzRtcp) if (fuzzRtcp)
......
...@@ -432,6 +432,7 @@ executable( ...@@ -432,6 +432,7 @@ executable(
'fuzzer/src/fuzzer.cpp', 'fuzzer/src/fuzzer.cpp',
'fuzzer/src/FuzzerUtils.cpp', 'fuzzer/src/FuzzerUtils.cpp',
'fuzzer/src/RTC/FuzzerDtlsTransport.cpp', 'fuzzer/src/RTC/FuzzerDtlsTransport.cpp',
'fuzzer/src/RTC/FuzzerRateCalculator.cpp',
'fuzzer/src/RTC/FuzzerRtpPacket.cpp', 'fuzzer/src/RTC/FuzzerRtpPacket.cpp',
'fuzzer/src/RTC/FuzzerRtpRetransmissionBuffer.cpp', 'fuzzer/src/RTC/FuzzerRtpRetransmissionBuffer.cpp',
'fuzzer/src/RTC/FuzzerRtpStreamSend.cpp', 'fuzzer/src/RTC/FuzzerRtpStreamSend.cpp',
......
...@@ -36,7 +36,10 @@ namespace RTC ...@@ -36,7 +36,10 @@ namespace RTC
MS_ASSERT( MS_ASSERT(
this->newestItemIndex != this->oldestItemIndex || this->oldestItemIndex == -1, this->newestItemIndex != this->oldestItemIndex || this->oldestItemIndex == -1,
"newest index overlaps with the oldest one"); "newest index overlaps with the oldest one [newestItemIndex:%" PRId32
", oldestItemIndex:%" PRId32 "]",
this->newestItemIndex,
this->oldestItemIndex);
// Set the newest item. // Set the newest item.
BufferItem& item = this->buffer[this->newestItemIndex]; BufferItem& item = this->buffer[this->newestItemIndex];
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论